从Sql Server数据库中选择数据时出现问题
大家好,
我遇到一个问题,从empdetails选择*"可以正常工作,但是从empdetails选择empName,其中empId ="sumit"和password ="12345''"需要更多的时间,之后会出现异常消息"ExecuterReader"需要一个开放且可用的连接.该连接的当前状态为关闭."
我在Web服务器上触发了这些命令(在我的本地PC上,两个命令都运行正常).
请帮帮我.
Hi Guys,
I am facing a problem, "select * from empdetails" working fine but "select empName from empdetails where empId=''sumit'' and password=''12345''" it takes much more time and after that gives exception message "ExecuterReader requires an open and available Connection. The Connection''s current state is closed."
i fire these command on web server( on my local pc both command working fine).
Please help me.
Thank you in advance!
在ExecuteReader()之前
试试这个
sqlconnection.Open();
Before ExecuteReader()
try this
sqlconnection.Open();
SqlConnection con =新的SqlConnection("Server =(local)\\ SQLEXPRESS; Initial Catalog = Northwind; Integrated Security = SSPI");
SqlCommand cmd =新的SqlCommand();
cmd.CommandText ="SELECT EmployeeID,FirstName +``''+ LastName作为来自员工的FullName";
cmd.Connection = con;
SqlConnection con = new SqlConnection("Server=(local)\\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=SSPI");
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT EmployeeID, FirstName + '' '' + LastName as FullName FROM Employees";
cmd.Connection = con;
if (con.State == System.Data.ConnectionState.Open)
{
con.Close();
}
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while(reader.Read()){
}
reader.Close();
con.Close();
或
还请检查下面的链接
http://forums.asp.net/post/4623355.aspx [
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read()) {
}
reader.Close();
con.Close();
or
also check below link
http://forums.asp.net/post/4623355.aspx[^]