Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!
Posted
Updated 3-Oct-11 21:11pm
v2
Comments
m@dhu 4-Oct-11 2:56am    
Error message tells to open the sqlconnection before command.ExecuteReader.
Karthik Harve 4-Oct-11 2:58am    
mention some of your code
Sunasara Imdadhusen 4-Oct-11 3:01am    
Please provide snippet of code!!
hitech_s 4-Oct-11 3:02am    
provide code so you can get solution easily
nagendrathecoder 4-Oct-11 3:03am    
Please show us some code snippet

Before ExecuteReader()

try this

sqlconnection.Open();
 
Share this answer
 
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;

C#
if (con.State == System.Data.ConnectionState.Open)
        {
            con.Close();
        }


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[^]
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900