Pages

Friday, 16 March 2012

How to find Datasource from Connection String?

Recently, I stumbled upon request to show data source property from Connection String to the end user. While, we can always split and parse the values, I was wondering about easy options for this and found 'OledbConnectionStringBuilder' class (Similar class available for SQL too)

To find Connection String parameters, just use it one of its method as below

return new OledbConnectionStringBuilder(ConnectionString).DataSource;

Simple and effective way to get the value..