Click here to Skip to main content
Click here to Skip to main content

Tagged as

Creating Connection String on-the-fly

, 26 Feb 2010
Rate this:
Please Sign up or sign in to vote.
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.)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Indrajeet Sutar
Software Developer (Junior) Excel Informatics, Pune
India India
Am Indrajeet T. Sutar. I am a web developer. I am working on .net technology. I have completed my Masters in Computers and Management (people call it as MCA, MBA etc.) Apart from programming i do photography (not regularly though), traveling and reading books.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 26 Feb 2010
Article Copyright 2010 by Indrajeet Sutar
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid