Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split Connection String

In a WinForm Application I Store My ConnectionString in App.Confing File.How Can I split this connectionstring to some Data like username,DataBaseName,Password and other thing Dynamically?

like image 353
Hossein Moradinia Avatar asked Aug 18 '11 10:08

Hossein Moradinia


2 Answers

I don't understand why all MSDN examples show ugly way by using Keys.

We can access primary data through properties:

SqlConnectionStringBuilder decoder = new SqlConnectionStringBuilder(connectionString);

string UserID = decoder.UserID; 
string Password = decoder.Password; 
like image 86
binball Avatar answered Sep 20 '22 19:09

binball


http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.aspx

And what you exactly need is: http://msdn.microsoft.com/en-us/library/d7z89tex.aspx

like image 41
Andrey Agibalov Avatar answered Sep 21 '22 19:09

Andrey Agibalov