using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Server;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
LoadAllSqlServer();
}
/**//// <summary>
/// 列出局域网中的所有数据库
/// </summary>
public static void LoadAllSqlServer()
{
SQLDMO.ApplicationClass app = new SQLDMO.ApplicationClass();
SQLDMO.NameList nameList =app.ListAvailableSQLServers();
if (nameList != null)
{
for (int i = 0; i < nameList.Count; i++)
{ Console.WriteLine(nameList.Item(i).ToString());\\提示出错 }
}
}
}
}提示
未处理NullReferenceException
未将对象引用设置到对象的实例。
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Server;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
LoadAllSqlServer();
}
/**//// <summary>
/// 列出局域网中的所有数据库
/// </summary>
public static void LoadAllSqlServer()
{
SQLDMO.ApplicationClass app = new SQLDMO.ApplicationClass();
SQLDMO.NameList nameList =app.ListAvailableSQLServers();
if (nameList != null)
{
for (int i = 0; i < nameList.Count; i++)
{ Console.WriteLine(nameList.Item(i).ToString());\\提示出错 }
}
}
}
}提示
未处理NullReferenceException
未将对象引用设置到对象的实例。
{
SQLDMO.Application app = new SQLDMO.Application();
SQLDMO.NameList Servers = null; Servers = app.ListAvailableSQLServers(); for (int i = 0; i < Servers.Count; i++)
{
object svr = Servers.Item(i + 1);
if (svr != null)
{
listBox1.Items.Add(svr);
} }
}