开发者

Getting initial catalog from the web.config file

I have a connecti开发者_Python百科on string in the web.config file. I have to get the database name from it. Let say my connection sting is

<add name="LocalSqlServer" connectionString="Data Source=XYZ;Initial Catalog=MyDataBase;Integrated Security=true" providerName="System.Data.SqlClient"/>

I want to get the database name [i.e. Initial Catalog] from the connection string.

How can I get it?


You can use the SqlConnectionStringBuilder for this purpose:

string connectionString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);

string database = builder.InitialCatalog;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜