Example #1
0
        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);
        }
Example #2
0
        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);
        }