SqlConnection conn = “***”
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " SELECT 工号 FROM PUB_User where 系统识别 = 3 and 工号='" + UserName.Text + "' and 口令='" + Password.Text + "' and md5='" + Md5 + "'";
cmd.Connection = conn; conn.Open();
SqlDataReader recu =cmd.ExecuteReader ();
///判断用户是否合法
if (recu.Read())
{
userId = recu["工号"].ToString().Trim();
}
recu.Close();
conn.Close();
Response.Write(userId);
Response.Redirect("~/Main.aspx");
//Response.Write("正确");
——————————————————————————————————————————————
代码如上,请高手赐教
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " SELECT 工号 FROM PUB_User where 系统识别 = 3 and 工号='" + UserName.Text + "' and 口令='" + Password.Text + "' and md5='" + Md5 + "'";
cmd.Connection = conn; 因为cmd属性已经设置连接了。
conn.Open();////////////这一行去掉SqlDataReader recu =cmd.ExecuteReader ();
///判断用户是否合法
if (recu.Read())
{
userId = recu["工号"].ToString().Trim();
}
recu.Close();
conn.Close();
Response.Write(userId);
Response.Redirect("~/Main.aspx");
//Response.Write("正确");
还能输出正确的userId对吗?
那是因为你的userId和conn没有关系.
然后显示 未打开连接
conn=data source=(local);uid=sa;pwd=123;database=YPZB
或者 conn=Data Source=(local);Initial Catalog=YPZB;Persist Security Info=True;User ID=sa;Password=123
------------------------
另外,我想知道你“sql还有一个连接啊??”表達的是什么意思?
是說還有一個連接一直與SQL Server服務器保持連接?
還是說還有一個SqlConnection?
我的后台sql2000数据库中,点击分离连接,显示有一个正在使用的连接~原提示:使用本数据库的连接 1
我感觉应该是交换完数据就把所有连接关闭了才对啊~不然,当多个用户同时登录时,服务器岂不是要死机吗?