Creating Connection String on-the-fly






1.89/5 (3 votes)
It is possible for us to create and manage Connection String at run time by using SqlConnectionStringBuilder class, So we can change connectionstring at any time. Example Code : SqlConnectionStringBuilder ConnBuild = new SqlConnectionStringBuilder();ConnBuild.DataSource =...
It is possible for us to create and manage Connection String at run time by using SqlConnectionStringBuilder class, So we can change connectionstring at any time.
Example Code :
SqlConnectionStringBuilder ConnBuild = new SqlConnectionStringBuilder(); ConnBuild.DataSource = "SQLExpress"; ConnBuild.ConnectTimeout = 1000; ConnBuild.IntegratedSecurity = true; //or ConnBuild.IntegratedSecurity = false; ConnBuild.UserID = "Indrajeeth"; ConnBuild.Password = "Indrajeeth"; Response.Write(cnbuilder.ConnectionString);Some important properties of connectionstringbuilder class InitialCatalog - Used for returning or setting name of the database related with the connection. IntegratedSecurity - sets or returns false - indicating user-id and password is specified. and sets or returns false when current windows account credentials are used for authentication UserID - Used for returning or setting user ID while connecting to SQL Server. Password - Gets or sets the password for the SQL Server account. ConnectTimeout - Used for setting or returing the time span (in seconds) for waiting connection to the server before terminating. DataSource - Used for setting or returing the name or network address for connecting of the instance of SQL Server. Encrypt - Returns or sets Boolean value for specifing whether SQL Server uses SSL encryption for all data sent between the client and server (applicable only when the server has a certificate installed.)