<add name="LocalsqlServer" connectionString="Data Source=XYZ;Initial Catalog=MyDataBase;Integrated Security=true" providerName="System.Data.sqlClient"/>
我想要获取数据库名称初始目录]从连接字符串。
我怎么可以得到它?
string connectionString = ConfigurationManager.ConnectionStrings["LocalsqlServer"].ConnectionString; sqlConnectionStringBuilder builder = new sqlConnectionStringBuilder(connectionString); string database = builder.InitialCatalog;