Exemple #1
0
        //this will Display all the Instances of the
        private static void DisplayData()
        {
            SqlDataSourceEnumerator instance =
                SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();

            foreach (System.Data.DataRow row in table.Rows)
            {
                foreach (System.Data.DataColumn col in table.Columns)
                {
                    Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
                }
                Console.WriteLine("============================");
            }
        }
Exemple #2
0
        private void cmbServidores_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbServidores.Text == "<Buscar mas ...>")
            {
                SqlDataSourceEnumerator Servidores = SqlDataSourceEnumerator.Instance;

                DataTable dttServidores = Servidores.GetDataSources();

                //--FFLORES--- Mediante la función GetDataSources, obtengo una tabla con la información de los servidores

                foreach (DataRow row in dttServidores.Rows)
                {
                    cmbServidores.Items.Add(row["ServerName"].ToString() + "\\" + row["InstanceName"].ToString());
                }
            }
        }
        private void Chip_Click(object sender, RoutedEventArgs e)
        {
            List <string> lst_NameSever = new List <string>();

            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable table = instance.GetDataSources();

            MessageBox.Show(table.Rows[0]["ServerName"].ToString() + "**" + table.Rows[0]["InstanceName"].ToString());

            foreach (DataRow dataRow in table.Rows)
            {
                lst_NameSever.Add(dataRow[0].ToString() + "\\" + dataRow[1].ToString());
            }

            cbb_SeverName.ItemsSource   = lst_NameSever;
            cbb_SeverName.SelectedIndex = 0;
        }
    static void Main()
    {
        // Retrieve the enumerator instance, and
        // then retrieve the data sources.
        SqlDataSourceEnumerator instance =
            SqlDataSourceEnumerator.Instance;

        System.Data.DataTable table = instance.GetDataSources();

        // Filter the sources to just show SQL Server 2012 instances.
        System.Data.DataRow[] rows = table.Select("Version LIKE '11%'");
        foreach (System.Data.DataRow row in rows)
        {
            Console.WriteLine(row["ServerName"]);
        }
        Console.WriteLine("Press any key to continue.");
        Console.ReadKey();
    }
Exemple #5
0
        private String searchSQLInstance()
        {
            string SQLServerName             = "";
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();

            // Retrieve the enumerator instance and then the data.

            foreach (System.Data.DataRow row in table.Rows)
            {
                if (row["InstanceName"].ToString() == "DATEV_DBENGINE")
                {
                    SQLServerName = row["ServerName"].ToString();
                }
            }
            return(SQLServerName);
        }
Exemple #6
0
        public List <string> PegarInstSQLRede()
        {
            List <string> servers = new List <string>();

            //DataTable dt = Microsoft.SqlServer.Management.Smo.SmoApplication.EnumAvailableSqlServers(false);

            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable dt = instance.GetDataSources();

            foreach (DataRow dtr in dt.Rows)
            {
                foreach (DataColumn dtc in dt.Columns)
                {
                    servers.Add(dtc.ColumnName + " - " + dtr[dtc]);
                }
            }
            return(servers);
        }
Exemple #7
0
        private void frmServer_Load(object sender, EventArgs e)
        {
            txtUser.Enabled = false;
            txtPass.Enabled = false;

            SqlDataSourceEnumerator instance =
                SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();
            cmbServer.DataSource    = table;
            cmbServer.DisplayMember = "ServerName";


            //  cmbServer.SelectedIndexChanged -= cmbServer_SelectedIndexChanged_1;


            //cmbServer.SelectedIndex = 0;
        }
Exemple #8
0
        private void GetDbServers()
        {
            if (!chkScanNetwork.Checked)
            {
                //RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL");
                //string[] array = (string[])registryKey.GetValueNames();
                //if (array.Length > 0)

                RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
                RegistryKey key     = baseKey.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL");

                foreach (string sqlInstance in key.GetValueNames())
                {
                    if (sqlInstance == "MSSQLSERVER")
                    {
                        ServerNames.Add(Environment.MachineName);
                    }
                    else
                    {
                        ServerNames.Add(Environment.MachineName + "\\" + sqlInstance);
                    }
                }
            }
            else
            {
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                DataTable dataSources            = instance.GetDataSources();
                DataRow[] array3 = dataSources.Select("");
                DataRow[] array4 = array3;
                for (int j = 0; j < array4.Length; j++)
                {
                    DataRow dataRow = array4[j];
                    if (dataRow["InstanceName"] is string)
                    {
                        ServerNames.Add(dataRow["ServerName"] + "\\" + dataRow["InstanceName"]);
                    }
                    else
                    {
                        ServerNames.Add(dataRow["ServerName"]);
                    }
                }
            }
            ServerNames.Sort();
        }
Exemple #9
0
        private void btnLoadServers_Click(object sender, EventArgs e)
        {
            try
            {
                ClassCoreUtility.CaluculateAll(PBarSQLServer);
                // Create a instance of the SqlDataSourceEnumerator class
                servers = SqlDataSourceEnumerator.Instance;

                // Fetch all visible SQL server 2000 or SQL Server 2005 instances
                tableServers = new DataTable();

                // Check if datatable is empty
                if (tableServers.Rows.Count == 0)
                {
                    // Get a datatable with info about SQL Server 2000 and 2005 instances
                    tableServers = servers.GetDataSources();


                    // List that will be combobox’s datasource
                    List <string> listservers = new List <string>();


                    // For each element in the datatable add a new element in the list
                    foreach (DataRow rowServer in tableServers.Rows)
                    {
                        // Server instance could have instace name or only server name,
                        // check this for show the name
                        if (String.IsNullOrEmpty(rowServer["InstanceName"].ToString()))
                        {
                            listservers.Add(rowServer["ServerName"].ToString());
                        }
                        else
                        {
                            listservers.Add(rowServer["ServerName"] + "\\" + rowServer["InstanceName"]);
                        }
                    }

                    // Set servers list to combobox’s datasource
                    this.cmbSQLServer.DataSource = listservers;
                }
            }
            catch (Exception ex)
            { ex.ToString(); }
        }
        //returns list of instances in network if "SQL Server Browser" service is runned
        public static List <BrowsableInstance> GetInstances()
        {
            List <BrowsableInstance> list = new List <BrowsableInstance>();

            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable table = instance.GetDataSources();

            foreach (DataRow row in table.Rows)
            {
                foreach (DataColumn dataColumn in table.Columns)
                {
                    Console.WriteLine("{0} = {1}", dataColumn.ColumnName, row[dataColumn]);
                }
                Console.WriteLine();
                list.Add(new BrowsableInstance(row["ServerName"].ToString(), row["InstanceName"].ToString(), row["Version"].ToString()));
            }

            return(list);
        }
        //list all SQL Servers on the network
        public static void GetTheVersionsOfSqlServer()
        {
            SqlDataSourceEnumerator sqldatasourceenumerator1 = SqlDataSourceEnumerator.Instance;
            DataTable datatable1 = sqldatasourceenumerator1.GetDataSources();

            foreach (DataRow row in datatable1.Rows)
            {
                Console.WriteLine("****************************************");
                //Server Name: Name of the server.
                Console.WriteLine("Server Name:" + row["ServerName"]);
                //Instance Name: Name of the SQL Server instance. If its a default instance then this is DBNull.
                Console.WriteLine("Instance Name:" + row["InstanceName"]);
                //Is Clustered: returns Yes, if Server is clustered, else No.
                Console.WriteLine("Is Clustered:" + row["IsClustered"]);
                //Version: returns the full version number of the server listed.
                Console.WriteLine("Version:" + row["Version"]);
                Console.WriteLine("****************************************");
            }
        }
Exemple #12
0
        public static List <string> GetSQLServerInstances()
        {
            List <string>           instancesSQL = new List <string>();
            SqlDataSourceEnumerator instance     = SqlDataSourceEnumerator.Instance;

            foreach (DataRow row in instance.GetDataSources().Rows)
            {
                string instanceName = row["InstanceName"].ToString();

                if (!String.IsNullOrEmpty(instanceName))
                {
                    string serverName   = row["ServerName"].ToString();
                    string instanceReal = String.Format("{0}\\{1}", serverName, instanceName);
                    instancesSQL.Add(instanceReal);
                }
            }

            return(instancesSQL);
        }
Exemple #13
0
        private List <string> _GetSqlServers(bool shouldSortList)
        {
            if (_list1 == null)
            {
                _list1 = new List <string>();
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                DataTable table = instance.GetDataSources();

                foreach (DataRow row in table.Rows)
                {
                    string item = null;
                    foreach (DataColumn col in table.Columns)
                    {
                        //Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
                        if (col.ColumnName.Equals("ServerName"))
                        {
                            item = item + string.Format
                                   (
                                @"{0}",
                                row[col]);
                        }
                        if (col.ColumnName.Equals("InstanceName"))
                        {
                            item = item + string.Format
                                   (
                                @"\{0}",
                                row[col]);
                        }
                    }
                    _list1.Add(item);
                    //Console.WriteLine("============================");
                }

                if (shouldSortList)
                {
                    _list1.Sort();
                }
                // AppMain.Cache.Insert("GetSqlServers", list1, null, Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(60));

                return(_list1);
            }
            return(_list1);
        }
Exemple #14
0
 private void GetAllServerName()
 {
     try
     {
         Cursor.Current = Cursors.WaitCursor;
         SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
         DataTable dtInstancesList        = new DataTable();
         dtInstancesList             = instance.GetDataSources().Select("", "ServerName ASC").CopyToDataTable();
         ddlServerName.DataSource    = dtInstancesList;
         ddlServerName.DisplayMember = "ServerName";
         ddlServerName.ValueMember   = "ServerName";
         ddlServerName.SelectedIndex = -1;
     }
     catch (Exception ex)
     {
         MessageBox.Show("No Server Found. \nPlease enter your server name or please try below options.\n . or (local)", "Connection Manager", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     Cursor.Current = Cursors.Default;
 }
Exemple #15
0
        private void cmServerName_DropDown(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                System.Data.DataTable   table    = instance.GetDataSources();

                cmServerName.DataSource    = table;
                cmServerName.DisplayMember = "ServerName";
                cmServerName.ValueMember   = "InstanceName";
                this.Cursor = Cursors.Default;
            }
            catch (Exception)
            {
                this.Cursor = Cursors.Default;
                MessageBox.Show("An error has occured while trying to connect to SQL Server. Please contact the administrator!", "Scan IN&OUT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemple #16
0
        public static List <string> GetInstances()
        {
            LogWriter               Log              = new LogWriter("----- Running GetInstances -----");
            List <string>           instances        = new List <string>();
            SqlDataSourceEnumerator serverEnumerator = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = serverEnumerator.GetDataSources();
            int count = 0;

            if (table.Rows.Count == 0)
            {
                MessageBox.Show("No servers / instances found. Are you sure you're connected?", "No servers found");
            }
            foreach (System.Data.DataRow row in table.Rows)
            {
                instances.Add((table.Rows[count][0]).ToString());
                count += 1;
            }
            return(instances);
        }
Exemple #17
0
        public ActionResult ConfigDB()
        {
            ConfigDBModel           model        = new ConfigDBModel();
            SqlDataSourceEnumerator instance     = SqlDataSourceEnumerator.Instance;
            DataTable             table          = instance.GetDataSources();
            string                ServerName     = Environment.MachineName;
            List <SelectListItem> ServerNameList = new List <SelectListItem>();

            foreach (DataRow row in table.Rows)
            {
                ServerNameList.Add(new SelectListItem
                {
                    Text  = ServerName + "\\" + row["InstanceName"].ToString(),
                    Value = ServerName + "\\" + row["InstanceName"].ToString()
                });
            }
            // ViewBag.ServerNameList = new SelectList(ServerNameList, "kaizen_type_id", "kaizen_type");
            ViewData["ServerNameList"] = ServerNameList;
            return(View(model));
        }
Exemple #18
0
        public static ArrayList GetSQLServers()
        {
            SqlDataSourceEnumerator sqlSource = SqlDataSourceEnumerator.Instance;
            DataTable dt         = sqlSource.GetDataSources();
            ArrayList serverList = new ArrayList();

            foreach (DataRow dr in dt.Rows)
            {
                if (string.IsNullOrEmpty(dr["InstanceName"].ToString()) || string.Compare(dr["InstanceName"].ToString(), "MSSQLSERVER") == 0)
                {
                    serverList.Add(dr["ServerName"].ToString());
                }
                else
                {
                    serverList.Add(string.Format("{0}\\{1}", dr["ServerName"].ToString(), dr["InstanceName"].ToString()));
                }
            }

            return(serverList);
        }
Exemple #19
0
        /// <summary>
        /// Création de la liste des menus SQL
        /// </summary>

        private void CreateSqlInstanceMenu()
        {
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable dbList = instance.GetDataSources();

            foreach (DataRow curServer in dbList.Rows)
            {
                string name = "";
                if (curServer["ServerName"] != null && curServer["ServerName"] != DBNull.Value)
                {
                    name = curServer["ServerName"].ToString();
                }
                if (curServer["InstanceName"] != null && curServer["InstanceName"] != DBNull.Value && curServer["InstanceName"].ToString() != string.Empty)
                {
                    name += "\\" + curServer["InstanceName"].ToString();
                }

                sqlList.Add(name);
            }
        }
Exemple #20
0
        public static List <string> GetAllSqlServerList()
        {
            List <string>           list     = new List <string>();
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable table = instance.GetDataSources();

            foreach (DataRow row in table.Rows)
            {
                if (row["ServerName"] != DBNull.Value && Environment.MachineName.Equals(row["ServerName"].ToString()))
                {
                    string item = row["ServerName"].ToString();
                    if (row["InstanceName"] != DBNull.Value || !string.IsNullOrEmpty(Convert.ToString(row["InstanceName"]).Trim()))
                    {
                        item += @"\" + Convert.ToString(row["InstanceName"]).Trim();
                    }
                    list.Add(item);
                }
            }
            return(list);
        }
        /// <summary>
        /// 1. ServerName - Name of the server.
        /// 2. InstanceName - Name of the server instance. Blank if the server is running as the default instance.
        /// 3. IsClustered - Indicates whether the server is part of a cluster.
        /// 4. Version - Version of the server (8.00.x for SQL Server 2000, and 9.00.x for SQL Server 2005).
        /// </summary>
        /// <returns></returns>
        public static IList <string> GetActiveServers()
        {
            Collection <string>     result             = new Collection <string>();
            SqlDataSourceEnumerator instanceEnumerator = SqlDataSourceEnumerator.Instance;
            DataTable instancesTable = instanceEnumerator.GetDataSources();

            foreach (DataRow row in instancesTable.Rows)
            {
                if (!string.IsNullOrEmpty(row["InstanceName"].ToString()))
                {
                    result.Add(string.Format(@"{0}\{1}", row["ServerName"], row["InstanceName"]));
                }
                else
                {
                    result.Add(row["ServerName"].ToString());
                }
            }

            return(result);
        }
        public static List <String> Get()
        {
            SqlDataSourceEnumerator sqlSource = SqlDataSourceEnumerator.Instance;

            DataTable dtSQLInstances = sqlSource.GetDataSources();

            List <String> lstSQLInstances = new List <string>();

            string serverName = null, instanceName = null;

            foreach (DataRow record in dtSQLInstances.Rows)
            {
                serverName   = record["ServerName"].ToString();
                instanceName = record["InstanceName"] != null ? record["InstanceName"].ToString() : "";

                lstSQLInstances.Add(String.IsNullOrEmpty(instanceName) ? serverName : serverName + "\\" + instanceName);
            }

            return(lstSQLInstances);
        }
Exemple #23
0
        void FillList()
        {
            EnableControls(false);
            this.listView_sqlServers.Items.Clear();
            ListViewItem item = new ListViewItem("正在获取SQL服务器信息 ...");

            this.listView_sqlServers.Items.Add(item);

            this.Update();

            this.listView_sqlServers.Items.Clear();

            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();


            foreach (System.Data.DataRow row in table.Rows)
            {
                string strServerName   = row["ServerName"].ToString();
                string strInstanceName = row["InstanceName"].ToString();
                string strIsClustered  = row["IsClustered"].ToString();
                string strVersion      = row["Version"].ToString();

                item = new ListViewItem(strServerName);

                item.SubItems.Add(strInstanceName);
                item.SubItems.Add(strIsClustered);
                item.SubItems.Add(strVersion);
                this.listView_sqlServers.Items.Add(item);

                // 如果和本地计算机名相同,并且没有instancename,则事项字体加粗
                if (strServerName == SystemInformation.ComputerName &&
                    String.IsNullOrEmpty(strInstanceName) == true)
                {
                    item.Font = new Font(item.Font, FontStyle.Bold);
                }
            }

            EnableControls(true);
        }
Exemple #24
0
        public DataTable GetConnection()
        {
            if (dtsqls.Rows.Count == 0)
            {
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                System.Data.DataTable   table    = instance.GetDataSources();

                DataColumn column1 = new DataColumn("Adi", typeof(String));
                DataColumn column2 = new DataColumn("Degeri", typeof(String));
                DataColumn column3 = new DataColumn("isUzakMakine", typeof(String));

                dtsqls.Columns.Add(column1);
                dtsqls.Columns.Add(column2);
                dtsqls.Columns.Add(column3);
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    DataRow roww   = dtsqls.NewRow();
                    string  servis = table.Rows[i][1].ToString() ?? "";
                    string  server = table.Rows[i][0].ToString() ?? "";
                    if (servis.Length > 0)
                    {
                        servis = "\\" + servis;
                    }
                    roww["Adi"]    = server + servis;
                    roww["Degeri"] = server + servis;
                    dtsqls.Rows.Add(roww);
                    if (System.Environment.MachineName == server)
                    {
                        roww["isUzakMakine"] = 1;
                    }
                    else
                    {
                        roww["isUzakMakine"] = 0;
                    }
                }
                cmbsqls.DisplayMember = "Adi";
                cmbsqls.ValueMember   = "Degeri";
                cmbsqls.DataSource    = dtsqls;
            }
            return(dtsqls);
        }
        private void SelectDatabase()
        {
            ObservableCollection <string> list       = new ObservableCollection <string>();
            ObservableCollection <string> Storedlist = new ObservableCollection <string>();
            // var connectionString = ConfigurationManager.ConnectionStrings["SASEntitiesEDM"].ConnectionString;
            // string connectionstring = "data source=108.168.203.227,7008;user id=SimpleAccounting;password=SimpleAccounting;";
            //string connectionstring = "data source=(LocalDb)\\MSSQLLocalDB;Trusted_Connection=True;Integrated Security=True;";

            ObservableCollection <string> Serverlist = new ObservableCollection <string>();
            SqlDataSourceEnumerator       instance   = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();
            foreach (System.Data.DataRow row in table.Rows)
            {
                if (row["ServerName"] != DBNull.Value && Environment.MachineName.Equals(row["ServerName"].ToString()))
                {
                    string item = string.Empty;
                    item = row["ServerName"].ToString();
                    if (row["InstanceName"] != DBNull.Value || !string.IsNullOrEmpty(Convert.ToString(row["InstanceName"]).Trim()))
                    {
                        item += @"\" + Convert.ToString(row["InstanceName"]).Trim();
                    }
                    Serverlist.Add(item);
                }
            }
            SelectServerName = Serverlist;
            System.Diagnostics.Process          process   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
            startInfo.WindowStyle                    = System.Diagnostics.ProcessWindowStyle.Hidden;
            startInfo.FileName                       = "cmd.exe";
            startInfo.Arguments                      = "/C sqllocaldb i";
            process.StartInfo                        = startInfo;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.CreateNoWindow         = true;
            process.Start();
            var    result          = process.StandardOutput.ReadLine();
            string LocalServerName = string.Concat(@"(LocalDb)\", result);

            SelectServerName.Add(LocalServerName);
        }
Exemple #26
0
        private static bool DataSourceExists(string dataSource)
        {
            bool result = dataSource == @"." || dataSource.Equals(@"localhost", StringComparison.InvariantCultureIgnoreCase);

            if (!result)
            {
                SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
                DataTable table = instance.GetDataSources();
                string[]  items = dataSource.Split('\\');
                if (items.Length == 1 || items.Length == 2)
                {
                    string serverName   = items[0];
                    string instanceName = items.Length == 1 ? string.Empty : items[1];
                    result = table.AsEnumerable()
                             .Any(r => (r.Field <string>(@"ServerName") ?? string.Empty).Equals(serverName, StringComparison.InvariantCultureIgnoreCase) &&
                                  (r.Field <string>(@"Instancename") ?? string.Empty).Equals(instanceName, StringComparison.InvariantCultureIgnoreCase));
                }
            }

            return(result);
        }
Exemple #27
0
        private void getNameServer()
        {
            string myServer = Environment.MachineName;
            // Retrieve the enumerator instance and then the data.
            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
            DataTable servers = instance.GetDataSources();

            if (servers.Rows.Count != 0)
            {
                cbbNameServer.DataSource    = servers;
                cbbNameServer.DisplayMember = "ServerName";
            }
            else
            {
                if (cbbNameServer.InvokeRequired)
                {
                    cbbNameServer.Invoke(new MethodInvoker(delegate { cbbNameServer.Items.Add(myServer); }));
                }
                // cbbNameServer.Items.Add(myServer);
            }
        }
Exemple #28
0
        /// <summary>
        /// Este método devuelve una lista con todos los Nombre de los Servidores
        /// disponibles en la RED actual;
        /// </summary>
        /// <returns>arreglo de string</returns>

        static public string[] Lista_ServidoresSQL()
        {
            string[] Lista = null;
            int      Cant  = 0;
            SqlDataSourceEnumerator instancia = SqlDataSourceEnumerator.Instance;
            DataTable tabla = instancia.GetDataSources();

            Lista = new string[tabla.Rows.Count];

            foreach (DataRow Registro in tabla.Rows)
            {
                foreach (DataColumn Columna in tabla.Columns)
                {
                    if (Columna.ColumnName == "ServerName")
                    {
                        Lista[Cant++] = Registro[Columna].ToString();
                    }
                }
            }
            return(Lista);
        }
        /// <summary>
        /// Retrive the Sql Servers List on the local network.
        /// </summary>
        private void GetListOfSQLServers()
        {
            DataTable objServerList;

            try
            {
                ServersList = new BindingList <Server>();

                SqlDataSourceEnumerator objDataSourceEnumInstance = SqlDataSourceEnumerator.Instance;

                objServerList = objDataSourceEnumInstance.GetDataSources();

                foreach (DataRow objServerData in objServerList.Rows)
                {
                    LoadServerToList(objServerData);
                }
            }
            catch (Exception Ex)
            {
                throw new Exception("Failed In Get the list of Data Source Servers", Ex);
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            cboServer.Items.Add(".");
            cboServer.Items.Add("(Local)");
            cboServer.Items.Add("LocalHost");
            cboServer.Items.Add(@".\SQLEXPRESS");
            //cboServer.Items.Add(string.Format(@"{0}\SQLEXPRESS", Environment.MachineName));
            cboServer.SelectedIndex            = 2;
            chkUseIntergaratedSecurity.Checked = true;
            if (chkUseIntergaratedSecurity.Checked)
            {
                txtPassword.Enabled = false;
                txtUsername.Enabled = false;
            }
            else
            {
                txtPassword.Enabled = true;
                txtUsername.Enabled = true;
            }

            SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;

            System.Data.DataTable table = instance.GetDataSources();

            foreach (System.Data.DataRow row in table.Rows)
            {
                cboServer.Items.Add(string.Format(@"{0}\SQLEXPRESS", row["ServerName"].ToString()));
                cboServer.Items.Add(string.Format(@"{0}", row["ServerName"].ToString()));
                //ServerName
                //txtRichTextBox.Text += row["ServerName"] + "\n";

                //foreach (System.Data.DataColumn col in table.Columns)
                //{
                //    //Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
                //    txtRichTextBox.Text += col.ColumnName + " " + row[col] + "\n";
                //}
            }
        }