Register
|
Articles
|
Questions
|
Projects
|
Asp.Net Tips
|
Free Magazines
|
Tutorials
|
Search
|
Write to us
|
Login
Search
Articles
Asp.Net 2.0
AJAX
ADO.Net
C#
Javascript
Books
Asp.Net 2.0
AJAX
ADO.NET
C#
JavaScript
MS SQL Server
SilverLight
VB.NET
XML
Web Service
Resources
Asp.Net News
Downloads
Free Tech Magazines
Asp.Net Web Hosting
Archives
Softwares
Newsletter
Suggest Us
Link to Us
Feeds Subscription
Articles
Questions & Answers
Tips & Tricks
How to Build ConnectionString at Run-Time/Dynamically
Posted by
Moderator1
on
6/16/2008 7:22:55 AM
4241
Views
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();
Response.Write("Connected.....");
Post New Tips/Tricks
View all Tips/Tricks
Featured Resources:
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
Integrating Silverlight 4 with SharePoint 2010 - Free 42 Page Sample Chapter
A free sample chapter from Packt Enterprise's book: Microsoft Silverlight 4 and SharePoint 2010 Integration.
100% Free Subscription until Stock lost.
View complete list.
Sponsored by
Home
About us
Contact Us
Links
Advertise
Privacy Policy
Copyright ©
2012
. www.AspdotnetCodes.com. All rights reserved.