1

I have an application using MSSQLSERVER,when I deploy it to the customer, the server name could change, so I have to change the connection string of my xpo data model at run time,

this is the class generated with the XPO data model

public static class ConnectionHelper {
        public const string ConnectionString = @"XpoProvider=MSSqlServer;data source=localhost;integrated security=SSPI;initial catalog=tkdoc";
        public static void Connect(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption) {
            XpoDefault.DataLayer = XpoDefault.GetDataLayer(ConnectionString, autoCreateOption);
            XpoDefault.Session = null;
        }
        public static DevExpress.Xpo.DB.IDataStore GetConnectionProvider(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption) {
            return XpoDefault.GetConnectionProvider(ConnectionString, autoCreateOption);
        }
        public static DevExpress.Xpo.DB.IDataStore GetConnectionProvider(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption, out IDisposable[] objectsToDisposeOnDisconnect) {
            return XpoDefault.GetConnectionProvider(ConnectionString, autoCreateOption, out objectsToDisposeOnDisconnect);
        }
        public static IDataLayer GetDataLayer(DevExpress.Xpo.DB.AutoCreateOption autoCreateOption) {
            return XpoDefault.GetDataLayer(ConnectionString, autoCreateOption);
        }
    }

I'd like to change the ConnectionString in case the server or the user name or the password change

Rad
  • 4,403
  • 4
  • 24
  • 25

1 Answers1

0

I suggest that you store the connection string in the application configuration file. This way, users can manually modify it, or you can provide them the special settings form for this purpose.

It is easy to read the connection string from the application configuration file. The code example can be found here on StackOverflow: Get connection string from App.config

Community
  • 1
  • 1
Uranus
  • 1,690
  • 1
  • 12
  • 22