OleDbConnection conn = new OleDbConnection("Provider=SQLOLEDB;Data Source=ZHOUCL;Integrated Security=SSPI;Initial Catalog=TestDW");
try
{
conn.Open();
}
catch (Exception ex)
{
Response.Write(ex.Message);
} String str="select 密码 from 用户表 where 用户名='"+TextBox1.Text+"'";
OleDbCommand cmd = new OleDbCommand(str, conn);
String result = (String)cmd.ExecuteScalar(); if (result == TextBox2.Text.ToString())
{
TextBox3.Text = "连接成功...";
} conn.Close();为什么我在VS里面直接调试没有问题,而我去在IE里面输入http://localhost/...的时候就出现:
ExecuteScalar 要求已打开且可用的连接。连接的当前状态为已关闭。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: ExecuteScalar 要求已打开且可用的连接。连接的当前状态为已关闭。源错误:
行 41: String str="select 密码 from 用户表 where 用户名='"+TextBox1.Text+"'";
行 42: OleDbCommand cmd = new OleDbCommand(str, conn);
行 43: String result = (String)cmd.ExecuteScalar();
行 44:
行 45: if (result == TextBox2.Text.ToString())
刚刚学习,不知道怎么解决这个问题!~
try
{
conn.Open();
}
catch (Exception ex)
{
Response.Write(ex.Message);
} String str="select 密码 from 用户表 where 用户名='"+TextBox1.Text+"'";
OleDbCommand cmd = new OleDbCommand(str, conn);
String result = (String)cmd.ExecuteScalar(); if (result == TextBox2.Text.ToString())
{
TextBox3.Text = "连接成功...";
} conn.Close();为什么我在VS里面直接调试没有问题,而我去在IE里面输入http://localhost/...的时候就出现:
ExecuteScalar 要求已打开且可用的连接。连接的当前状态为已关闭。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.InvalidOperationException: ExecuteScalar 要求已打开且可用的连接。连接的当前状态为已关闭。源错误:
行 41: String str="select 密码 from 用户表 where 用户名='"+TextBox1.Text+"'";
行 42: OleDbCommand cmd = new OleDbCommand(str, conn);
行 43: String result = (String)cmd.ExecuteScalar();
行 44:
行 45: if (result == TextBox2.Text.ToString())
刚刚学习,不知道怎么解决这个问题!~
OleDbConnection conn = new OleDbConnection("Provider=SQLOLEDB;Data Source=ZHOUCL;Integrated Security=SSPI;Initial Catalog=TestDW");
try
{
conn.Open();
}
catch (Exception ex)
{
Response.Write(ex.Message);
} String str="select 密码 from 用户表 where 用户名='"+TextBox1.Text+"'";
OleDbCommand cmd = new OleDbCommand(str, conn);
conn.Open(); //打开数据库连接
String result = (String)cmd.ExecuteScalar(); if (result == TextBox2.Text.ToString())
{
TextBox3.Text = "连接成功...";
} conn.Close();
try
{
String str="select 密码 from 用户表 where 用户名='"+TextBox1.Text+"'";
OleDbCommand cmd = new OleDbCommand(str, conn);
conn.Open();
String result = (String)cmd.ExecuteScalar(); if (result == TextBox2.Text.ToString())
{
TextBox3.Text = "连接成功...";
} conn.Close(); }
catch (Exception ex)
{
Response.Write(ex.Message);
}
所以conn.Close();时错了,因为你根本就没打开,就去关闭,所以出错了。