How to Build ConnectionString at Run-Time/Dynamically in ADO.Net
SqlConnectionStringBuilder is a class that helps to create and manage connection strings at run-time. You can change any connection string setting through your code whenever and wherever you want.
Sample Code for SqlConnectionStringBuilder:
SqlConnectionStringBuilder cnbuilder = new SqlConnectionStringBuilder();
cnbuilder.DataSource = "MyServerName";
cnbuilder.ConnectTimeout = 1000;
cnbuilder.IntegratedSecurity = false;
cnbuilder.UserID = "sa";
cnbuilder.Password = "MyDBServerPassword";
Response.Write(cnbuilder.ConnectionString);
The above block of code, create a connectionstring based on the values you passed to the DataSource, UserId and Password fields. You can directly use this SqlConnectionStringBuilder object to open a connection as follows
SqlConnection cn = new SqlConnection(cnbuilder.ConnectionString);
cn.Open();
This link is for Creating Class file fire DataAccess Leayer not For Above Stuff.
Data Access layer
Sample Code for SqlConnectionStringBuilder:
SqlConnectionStringBuilder cnbuilder = new SqlConnectionStringBuilder();
cnbuilder.DataSource = "MyServerName";
cnbuilder.ConnectTimeout = 1000;
cnbuilder.IntegratedSecurity = false;
cnbuilder.UserID = "sa";
cnbuilder.Password = "MyDBServerPassword";
Response.Write(cnbuilder.ConnectionString);
The above block of code, create a connectionstring based on the values you passed to the DataSource, UserId and Password fields. You can directly use this SqlConnectionStringBuilder object to open a connection as follows
SqlConnection cn = new SqlConnection(cnbuilder.ConnectionString);
cn.Open();
This link is for Creating Class file fire DataAccess Leayer not For Above Stuff.
Data Access layer
Labels: ADO.Net, asp.net, C#.Net, ConnectionStrings in ado.net, database, odbc, oledb, oracle, sqlserver, system.data.sqlclient.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home