public void sFillListAvailableSQLServers() { //DataTable a = default(DataTable); //DataRow vRow = default(DataRow); //SmoApplication oSQLApp = default(SmoApplication); //oSQLApp = new SmoApplication(); //a = oSQLApp.EnumAvailableSqlServers; //foreach ( vRow in a.Rows) { // TXT_ServerName.Items.Add(vRow(0)); //} System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance; System.Data.DataTable dataTable = instance.GetDataSources(); string myServer = Environment.MachineName; //DataTable servers = SqlDataSourceEnumerator.Instance.GetDataSources(); for (int i = 0; i < dataTable.Rows.Count; i++) { if (myServer == dataTable.Rows[i]["ServerName"].ToString()) ///// used to get the servers in the local machine//// { if ((dataTable.Rows[i]["InstanceName"] as string) != null) { TXT_ServerName.Items.Add(dataTable.Rows[i]["ServerName"] + "\\" + dataTable.Rows[i]["InstanceName"]); } else { TXT_ServerName.Items.Add(dataTable.Rows[i]["ServerName"]); } } } }
///<summary>SQLServerInstance</summary> public static DataTable SQLServerInstance() { System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance; System.Data.DataTable dataTable = instance.GetDataSources(); /* #if (DEBUG) * foreach( DataRow dataRow in dataTable.Rows ) * { * foreach (System.Data.DataColumn dataColumn in dataTable.Columns) * { * System.Console.WriteLine("{0} = {1}", dataColumn.ColumnName, dataRow[dataColumn]); * } * } #endif */ return(dataTable); }
public DataTable GetServerName() { System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance; System.Data.DataTable table = instance.GetDataSources(); return(table); }
private void Form1_Load(object sender, EventArgs e) { System.Data.Sql.SqlDataSourceEnumerator instance = System.Data.Sql.SqlDataSourceEnumerator.Instance; System.Data.DataTable dataTable = instance.GetDataSources(); int count = dataTable.Rows.Count; }