public ArrayList GetServerList() { ArrayList arrayLists = new ArrayList(); SQLDMO.Application applicationClass = new Application(); try { try { NameList nameList = applicationClass.ListAvailableSQLServers(); for (int i = 1; i <= nameList.Count; i++) { arrayLists.Add(nameList.Item(i)); } } catch (Exception exception) { throw new Exception(string.Concat("取数据库服务器列表出错:", exception.Message)); } } finally { applicationClass.Quit(); } return(arrayLists); }
private void Form1_Load(object sender, EventArgs e) { SQLDMO.Application app = new SQLDMO.Application(); SQLDMO.NameList sqlList = app.ListAvailableSQLServers(); for (int i = 1; i < sqlList.Count; i++) { cmbServer.Items.Add(sqlList.Item(i)); } SetText(); }
private void getSqlServer() {//获取数据库服务器列表 SQLDMO.Application SQLServer = new SQLDMO.Application(); SQLDMO.NameList strServerList = SQLServer.ListAvailableSQLServers(); if (strServerList.Count > 0) { for (int i = 0; i < strServerList.Count; i++) { cbbSqlServerName.Items.Add(strServerList.Item(i + 1));//将找到的服务器添加到comboBox中显示 } } }
public ArrayList GetDbList(string string_3, string string_4, string string_5) { this.ServerName = string_3; this.UserName = string_4; this.Password = string_5; ArrayList arrayLists = new ArrayList(); SQLDMO.Application applicationClass = new Application(); SQLServer sQLServerClass = new SQLServer(); try { try { sQLServerClass.Connect(this.ServerName, this.UserName, this.Password); foreach (Database databasis in sQLServerClass.Databases) { if (databasis.Name == null) { continue; } arrayLists.Add(databasis.Name); } } catch (Exception exception) { throw new Exception(string.Concat("连接数据库出错:", exception.Message)); } } finally { sQLServerClass.DisConnect(); applicationClass.Quit(); } return(arrayLists); }
public SQLObject() { SQLApp = new SQLDMO.Application(); InitializeComponent(); }