请教一下,我编写了一个针对数据库行,统计数量的小软件,代码和软件界面如下,访问与统计其他数据库都没问题,但其中一个生产数据库,只成功统计过几次,后面总是报错如下,请问是什么原因呢,请给排查一下,谢谢;
```c#
private void button5_Click(object sender, EventArgs e)
{
String connectionString = String.Format("server={0};uid={1};pwd={2};", textBoxHost.Text, textBoxUser.Text, textBoxPassword.Text);
string query = "SELECT name from sys.databases where name NOT IN ('master', 'tempdb', 'model', 'msdb')";
SqlConnection sqlconn = new SqlConnection(connectionString);
sqlconn.Open();
try
{
MessageBox.Show("数据库连接成功!");
//查询条件和SqlConnection连接
//SqlCommand cmd = new SqlCommand(SqlString, sqlconn);
//数据适配器
//SqlDataAdapter sda = new SqlDataAdapter();
//sda.SelectCommand = cmd;
//DataTable存储数据
//DataTable dt = new DataTable();
//sda.Fill(dt);
//dataGridView1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show("数据库连接失败,请填写准确连接参数");
return;
}
finally
{
conn.Close();
}
// 清空下拉列表
comboBox1.Items.Clear();
using (SqlConnection connection = new SqlConnection(connectionString))
{
try
{
connection.Open();
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string dbName = reader.GetString(0);
comboBox1.Items.Add(dbName);
//清空前将首选项设置为更新后的第一项;
comboBox1.SelectedIndex = 0;
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
}
}
}
```