Example #1
0
        // 在用户的配置时,我们需要列出当前局域网内所有的数据库服务器,并且要列出指定服务器的所有数据库,实现代码如下:
        // 取得数据库服务器列表:

        /// <summary>
        /// 获取数据库服务器列表
        /// </summary>
        /// <returns></returns>
        public static ArrayList GetServerList(out bool isErr)
        {
            ArrayList allServers = new ArrayList();

            try
            {
                SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
                // 将局域网类的所有能够连接SQL的服务器名称列出
                SQLDMO.NameList serverList = sqlApp.ListAvailableSQLServers();

                allServers.Add("(local)");
                for (int i = 1; i <= serverList.Count; i++)
                {
                    // 添加到列表中
                    allServers.Add(serverList.Item(i));
                }
                sqlApp.Quit();
                isErr = true;
            }
            catch (Exception e)
            {
                isErr = SqlErrRepair(e.Message.ToString());
                return(GetServerList(out isErr));
            }
            return(allServers);
        }
Example #2
0
        private void comboBox1_DropDown(object sender, System.EventArgs e)
        {
            Cursor oldCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                if (comboBox1.Items.Count == 0)
                {
                    SQLDMO.SQLServer server = new SQLDMO.SQLServerClass();
                    SQLDMO.NameList  names  = server.Application.ListAvailableSQLServers();
                    for (int i = 0; i < names.Count; ++i)
                    {
                        string s = Convert.ToString(names.Item(i));
                        if (s != null)
                        {
                            comboBox1.Items.Add(s);
                        }
                    }
                }
            }
            finally
            {
                Cursor.Current = oldCursor;
            }
        }
Example #3
0
        private IFrmMain frmMain  = null;       //主窗体

        #endregion


        #region [ 事件: 窗体加载 ]

        /// <summary>
        /// 窗体加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmSqlList_Load(object sender, EventArgs e)
        {
            SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass(); //分布式管理对象

            try
            {
                SQLDMO.NameList serverList = sqlApp.ListAvailableSQLServers();//获取服务器名称列表

                if (serverList.Count > 0)
                {
                    for (int i = 1; i <= serverList.Count; i++)
                    {
                        ltbServer.Items.Add(serverList.Item(i));//绑定到ListBox
                    }
                }
                else
                {
                    ltbServer.Items.Add("(local)"); //如果没有活动的服务器,加载本机
                }

                ltbServer.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                ErrorMessage(3010010, ex.StackTrace, "[FrmDBSet:LoadSqlList]", ex.Message);
                //3010010frmMain.ErrorMessage(ee.Message, true, false);
            }
            finally
            {
                sqlApp.Quit();
            }
        }
Example #4
0
        public ArrayList GetServerList()
        {
            ArrayList alServers = new ArrayList();

            SQLDMO.Application sqlApp = new SQLDMO.ApplicationClass();
            try
            {
                SQLDMO.NameList serverList = sqlApp.ListAvailableSQLServers();
                for (int i = 1; i <= serverList.Count; i++)
                {
                    alServers.Add(serverList.Item(i));
                    //comboBox1.Items.Add(serverList.Item(i));
                    //listBox1.Items.Add(serverList.Item(i));
                }
            }
            catch (Exception e)
            {
                throw (new Exception("Take the database server list error:" + e.Message));
            }
            finally
            {
                sqlApp.Quit();
            }
            return(alServers);
        }
Example #5
0
        //获取SQL服务器列表
        public ArrayList GetSqlServerList()
        {
            ArrayList list = new ArrayList();

            SQLDMO.Application sqlApp     = new SQLDMO.Application();
            SQLDMO.NameList    ServerName = sqlApp.ListAvailableSQLServers();
            for (int i = 0; i < ServerName.Count; i++)
            {
                list.Add(ServerName.Item(i + 1));
            }
            return(list);
        }
Example #6
0
        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));
                }
            }
        }
Example #7
0
 private void Form2_Load(object sender, EventArgs e)
 {
     listBox1.Items.Clear();
     SQLDMO.Application SQLServer = new SQLDMO.Application();
     SQLDMO.NameList    strServer = SQLServer.ListAvailableSQLServers();
     if (strServer.Count > 0)
     {
         for (int i = 0; i < strServer.Count; i++)
         {
             listBox1.Items.Add(strServer.Item(i + 1));
         }
     }
 }
Example #8
0
 private void button1_Click(object sender, EventArgs e)
 {
     listBox1.Items.Clear();
     sqlServers = sqlApp.ListAvailableSQLServers();
     if(sqlServers != null)
     {
         for(int i=0;i<sqlServers.Count;i++)
         {
             object srv = sqlServers.Item( i + 1);
             //添加到服务器的列表中去
             this.listBox1.Items.Add(srv.ToString());
         }
     }
 }
 /// <summary>
 /// Get Server List By SQLDMO Com
 /// </summary>
 private void InitServerList()
 {
     this.cboxServerList.Items.Clear();
     SQLDMO.Application sqlApp     = new SQLDMO.Application();
     SQLDMO.NameList    sqlServers = sqlApp.ListAvailableSQLServers();
     for (int i = 0; i < sqlServers.Count; i++)
     {
         object srv = sqlServers.Item(i + 1);
         if (srv != null)
         {
             this.cboxServerList.Items.Add(srv);
         }
     }
     if (this.cboxServerList.Items.Count > 0)
     {
         this.cboxServerList.SelectedIndex = 0;
     }
     else
     {
         this.cboxServerList.Text = "<No available SQL Servers>";
     }
 }
        /// <summary>
        /// Handles the DropDown event of the comboBoxSqlServer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void comboBoxSqlServer_DropDown(object sender, EventArgs e)
        {
            comboBoxSqlServer.Items.Clear();

            Application.UseWaitCursor = true;

            try
            {
                SQLDMO.ApplicationClass app     = new SQLDMO.ApplicationClass();
                SQLDMO.NameList         servers = app.ListAvailableSQLServers();

                for (int i = 1; i <= servers.Count; i++)
                {
                    comboBoxSqlServer.Items.Add(servers.Item(i));
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, "Mediachase.Ibn.ConfigurationUI.SQLDMO");
            }

            Application.UseWaitCursor = false;
        }