根据服务名称,获取sql server 里的数据库表名
时间:2011-02-15 来源:我的食草堂
public List<string> GetMSSQLDBNameList(string DSN, string UID, string PWD)
{
List<string> databases=new List<string> ();
SqlConnection Connection = new SqlConnection(String.Format("Data Source={0};Initial Catalog=master;User ID={1};PWD={2}", DSN, UID, PWD));
DataTable DBNameTable = new DataTable();
//从系统表master..sysdatabases中查询数据库名字
SqlDataAdapter Adapter = new SqlDataAdapter("select name from master..sysdatabases", Connection);
Adapter.Fill(DBNameTable);
foreach (DataRow Row in DBNameTable.Rows)
{
databases.Add(Row[0].ToString());
}
return databases;
}
public List<string> GetMSSQLDBNameList(string DSN)
{
List<string> databases = new List<string>();
SqlConnection Connection = new SqlConnection(String.Format("Data Source={0};Initial Catalog=master;Integrated Security=True", DSN));
DataTable DBNameTable = new DataTable();
SqlDataAdapter Adapter = new SqlDataAdapter("select name from master..sysdatabases", Connection);
Adapter.Fill(DBNameTable);
foreach (DataRow Row in DBNameTable.Rows)
{
databases.Add(Row[0].ToString());
}
return databases;
}