Search
Categories
  ASP.NET
Visual C#
Visual Basic
.NET Framework
ADO.NET
AJAX
LINQ
Java
 
Tutorial Rating
 
3.9 out of 5


Total Votes: 10
         
1 2 3 4 5
 




Using SqlConnectionStringBuilder class in C#

Author: Waqas Anwar - Posted Date: 16-May-2008 - Category: ADO.NET   
Bookmark and Share
Microsoft introduced a new class in ADO.NET 2.0 version which can be used to build database connection strings specific to the provider you are using in ADO.NET. Different database providers expose different properties for the connection strings. For example, SQL Server connection string properties are different than MySql or OleDb connection strings. Although, it is possible to concatenate strings to build a complete connection string but by using .NET connection string builder class you don't need to memorize the properties appropriate to specific provider.
 
In the following tutorial, I will show you how you can use SqlConnectionStringBuilder class available in System.Data.SqlClient namespace to build a simple connection string. 

SqlConnectionStringBuilder

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();

builder.DataSource = TextBox1.Text;
builder.InitialCatalog = TextBox2.Text;
builder.UserID = TextBox3.Text;
builder.Password = TextBox4.Text;

TextBox5.Text = builder.ConnectionString;


Other than above mentioned four basic properties SqlConnectionStringBuilder also provides following common properties which can be used to build connection string with more options.

AsynchronousProcessing
AttachDBFilename
IntegratedSecurity
MaxPoolSize
MinPoolSize
MultipleActiveResultSets
PacketSize
Pooling
UserInstance
WorkstationID



RELATED TUTORIALS

  Connection String Encryption in Web.config using C#
  Connection String Encryption in Web.config using VB.NET
  Storing Database Connection Strings in App.Config

LEAVE YOUR COMMENTS LEAVE YOUR COMMENTS
 Name (required)  
 Email (required
 Website


 
POSTED COMMENTS POSTED COMMENTS

sir
i want to know that how to use Datalist control . Actually i want to show the category list through db .
Posted by Huma on Wednesday, March 11, 2009

I want to know, How can I check that "file or file path" is correct before opening the connection. So that exception may not accur.
Posted by Nice Guy on Monday, September 07, 2009

string filePath = "C:\\abc.txt";
FileInto file = new FileInfo(filePath);

if(file.Exists())
{
// Process your File here.
}
Posted by Waqas Anwar on Monday, September 07, 2009

Sir I request you, please add more in this tutorial about storing this connection string into app.config or web.config.
Posted by Gentleman on Friday, April 23, 2010

 


 
 
 

Categories

My Portfolio

Website Links


Copyright @ 2009 EzzyLearning.com