Creating ConnectionString with SqlConnectionStringBuilder Class in C#

The SqlConnectionStringBuilder was introduces in .NET 2.0 that is used to build the database connection string specific for the SQL Server .

The MSDN defines it as “Provides a simple way to create and manage the contents of connection strings used by the SqlConnection class. ”

The SqlConnectionStringBuilder is defined in the namespace System.Data.SqlClient and can help you build the connection string or even parse an existing connection string to retreive the properties .

private void Form1_Load(object sender, EventArgs e)
     SqlConnectionStringBuilder connectionString = new SqlConnectionStringBuilder();
     connectionString.DataSource = @".\SQLEXPRESS";
     connectionString.InitialCatalog = "MyDatabase";
     connectionString.IntegratedSecurity = true;

Some other notable properties that SqlConnectionStringBuilder provides include

  • AsynchronousProcessing to indicate if the asynchronous processing is allowed for the connection .
  • UserID – Username for the SQL Server
  • Password – Password for the SQL Server
  • etc.


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.


  1. bi May 28, 2011 Reply
  2. Creating ConnectionString with SqlConnectionStringBuilder Class in C# August 8, 2011 Reply
  3. johny August 9, 2011 Reply

Leave a Reply


Interesting BlogPosts to read

How to get an Enumerator from range of elements from ArrayList in C# ?
The code snippet shown in this blog post demonstrates how you can get the enumeraor from a range of ...
How to check for the column name in an SqlDataReader Object in C# ?
When working in ADO.NET for data access , there are times when you want to check to see if a column ...
Bing Search displays few school boards exam results
Looks like Bing now has a new feature that displays the results of various exams within Bing directl...