连接数据库
发表在C#图书答疑
2014-04-19
是否精华
是
否
版块置顶:
是
否
try
{
//Data Source=TAOYU-PC;Database=数据库名;Integrated Security=true;
string Constr = "Data Source = 3MVZYGDVTI2RBLK\\SQLEXPRESS;Database=" + textBox1.Text.Trim() + ";Integrated Security=true";
SqlConnection conn = new SqlConnection(Constr);
conn.Open();
if (conn.State == ConnectionState.Open)
{
label1.Text = "数据库【" + textBox1.Text.Trim() + "】已经连接并打开";
}
}
catch
{
MessageBox.Show("连接数据库失败");
}
服务器名称没有错,为什么还是连不上数据库呢?windows 下连接
{
//Data Source=TAOYU-PC;Database=数据库名;Integrated Security=true;
string Constr = "Data Source = 3MVZYGDVTI2RBLK\\SQLEXPRESS;Database=" + textBox1.Text.Trim() + ";Integrated Security=true";
SqlConnection conn = new SqlConnection(Constr);
conn.Open();
if (conn.State == ConnectionState.Open)
{
label1.Text = "数据库【" + textBox1.Text.Trim() + "】已经连接并打开";
}
}
catch
{
MessageBox.Show("连接数据库失败");
}
服务器名称没有错,为什么还是连不上数据库呢?windows 下连接