任何人都可以解释我什么,我错了,我做了下面这段code:
Can anybody explain me what I wrong I am doing in the following piece of code:
DataTable dt=SmoApplication.EnumAvailableSqlServer(true);
Server sr = new Server("Test");
foreach(DataBase db in sr.DataBases)
{
Console.WriteLine(db["name"]);
}
这给出了 sr.Databases
的异常无法连接。
看看下面的链接,他们可能会有所帮助:
Take a look at the following links they may be helpful:
在C#中枚举SQL Server实例,使用ODBC How获得使用C#(MSDN) 可用的SQL服务器的列表 填充SQL服务器的列表 Enumerate SQL Server Instances in C#, Using ODBC How to get a list of available SQL Servers using C# (MSDN) Populating a list of SQL Servers另外,你可以改变你的code到这一点:
Alternatively you could change your code to this:
DataTable dt = SmoApplication.EnumAvailableSqlServers(false);
if (dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
Console.WriteLine(dr["Name"]);
}
}
希望这能解决你的问题。
Hope this solves your problem.