C#获取指定数据库服务器下某用户可访问的数据库列表

代码如下:

           SqlConnection conn = new SqlConnection("server=数据库服务器名;uid=sa;pwd=sa");
            SqlCommand cmd = new SqlCommand("select name from sys.databases",conn);
            try
            {
                conn.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    cbxDBList.Items.Add(dr[0]);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                conn.Close();
            }

 

 

posted @ 2011-06-18 17:47  liancs  阅读(182)  评论(0编辑  收藏  举报