ADO.NET 2's SqlConnectionStringBuilder

The ADO.NET team is working on a building an object called SqlConnectionStringBuilder. The object is intended to assist in building connections string. Pretty basic concept and if you use config files to store your connection strings, you may not take advantage of it (but still could). But if you are writing code that concatenates strings into a connection string, you might want to check out this blog by Sushil Chordia from the ADO.NET team. pretty cool stuff!

The code would work like this:

SqlConnectionStringBuilderpublic void AccessData(string serverName, string uid, string pwd)
{
    SqlConnectionStringBuilder sqlConStrBldr = new SqlConnectionStringBuilder();
    sqlConStrBldr.DataSource = serverName;
    sqlConStrBldr.UserID = uid;
    sqlConStrBldr.Password = pwd;
    SqlConnection cn = new SqlConnection (sqlConStrBldr.ConnectionString);
    cn.Open();
    ...
    ...
    ...
    cn.Close();
}

On a scale of 1 - 5, WOW! factor of  2. But still very useful. Sometimes simple is better!

<P class=MsoNormal style=”MARGIN: 0in 0in 0pt”> </P>

Tweet Post Share Update RSS

Hi, I'm John Papa. I author this blog, create courses for Pluralsight and am a Google Developer Expert and Microsoft Regional Director. I travel speaking at events and train technology thought leaders

Tags:
All