添加引用sqldmo.dll
安装了SqlServer2000 就有了,在添加引用中找它
最好使用SQL Server 2000的SP3的sqldmo.dll
using SQLDMO;
SQLDMO.ApplicationClass sqlApp = new SQLDMO.ApplicationClass();
SQLDMO.NameList nameList;
int i = 0;
nameList = sqlApp.ListAvailableSQLServers();
for(i=1;i<nameList.Count;i++)
{
MessageBox.Show(nameList.Item(i).ToString());
}
获得SQLServer中所有的数据库表
SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
SQLDMO.SQLServer server = new SQLDMO.SQLServerClass();
server.Connect(Host_ComboBox.Text,UID_Text.Text.Trim(),PWD_Text.Text.Trim());
for(int i=1; i<=server.Databases.Count;i++)
{
MessageBox.Show(server.Databases.Item(i,"sa").Name);
}