我在SQL2005中建了一个数据库asp.net,并创建了一个登录名asp.net,密码为123,SQL中的服务器显示MYCOMPUTER\\SQLEXPRESS,我在VS2005中写字符串的时候如下,怎么会出现了说CONNECTION尚未初如化,是我的字符串写错了吗?
public class DB
{
public DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public bool findman()
{
SqlConnection con = new SqlConnection("Data Source=MYCOMPUTER\\SQLEXPRESS; Initial Catalog=asp.net;User ID=asp.net;password=123");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from user where id = 4 ");
int count1 = Convert.ToInt32(cmd.ExecuteScalar());
if (count1 > 0)
{
return true;
}
else
{
return false;
}
}
}
public class DB
{
public DB()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public bool findman()
{
SqlConnection con = new SqlConnection("Data Source=MYCOMPUTER\\SQLEXPRESS; Initial Catalog=asp.net;User ID=asp.net;password=123");
con.Open();
SqlCommand cmd = new SqlCommand("select count(*) from user where id = 4 ");
int count1 = Convert.ToInt32(cmd.ExecuteScalar());
if (count1 > 0)
{
return true;
}
else
{
return false;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货