-1
我在登錄屏幕中有一個組合框。在該組合框中,我需要數據庫的名稱。如何才能做到這一點?請幫助如何通過asp.net中的webconfig獲取數據庫名稱列表mvc4
我在登錄屏幕中有一個組合框。在該組合框中,我需要數據庫的名稱。如何才能做到這一點?請幫助如何通過asp.net中的webconfig獲取數據庫名稱列表mvc4
可以得到config文件中定義的連接字符串列表中使用System.Configuration.ConfigurationManager.ConnectionString屬性:
// Get the ConnectionStrings section.
// This function uses the ConnectionStrings
// property to read the connectionStrings
// configuration section.
public static void ReadConnectionStrings()
{
// Get the ConnectionStrings collection.
ConnectionStringSettingsCollection connections =
ConfigurationManager.ConnectionStrings;
if (connections.Count != 0)
{
Console.WriteLine();
Console.WriteLine("Using ConnectionStrings property.");
Console.WriteLine("Connection strings:");
// Get the collection elements.
foreach (ConnectionStringSettings connection in
connections)
{
string name = connection.Name;
string provider = connection.ProviderName;
string connectionString = connection.ConnectionString;
Console.WriteLine("Name: {0}",
name);
Console.WriteLine("Connection string: {0}",
connectionString);
Console.WriteLine("Provider: {0}",
provider);
}
}
else
{
Console.WriteLine();
Console.WriteLine("No connection string is defined.");
Console.WriteLine();
}
}
記得添加引用System.Configuration
組裝。
哪裏在保持您的數據庫配置? –