My Technical Notes

Tuesday, 13 May 2014

Parsing a Connection String using C#

Code to parse an arbitrary connection string:


Name=Tahir Hassan;Profession=Programmer;Mood=Happy
Code:

var connString = "Name=Tahir Hassan;Profession=Programmer;Mood=Happy";
var builder = new System.Data.Odbc.OdbcConnectionStringBuilder();
builder.ConnectionString = connString;
string Name = builder["Name"].ToString();
string Profession = builder["Profession"].ToString();
string Mood = builder["Mood"].ToString();

No comments: