Click here to Skip to main content
15,903,175 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello,

I am trying to connect to the Database from the application and its not happening at all. The same DLL is working fine in QA and production.

When debugging I understood the SQL connection is always closed.

when I checked the below line of code,

public static SqlConnection objConn = new SqlConnection(strConnStr);

For objConn I was able to see an exception "'ObjConn_serverversion' threw an exception of type System.InvalidOperationException" and the state was CLOSED.

Please let us know whether you can help me with this.

Connection String:
HTML
<add name="Connection" connectionstring="Data Source=xxx;Initial Catalog=xxx;Integrated Security=True;Trusted_Connection=true" providername="System.Data.SqlClient" />



During debug I found the below error message in objConn
C#
public static SqlConnection objConn = new SqlConnection(strConnStr);


ServerVersion --> 'objConn.ServerVersion' threw an exception of type 'System.InvalidOperationException'

State --> Closed

Source code was initially developed in VS 2008. Now when I opened the solution it automatically takes me to Visual studio 2010 Conversion wizard, I am not sure whether this is something to do with this.
Posted
Updated 15-Apr-15 21:40pm
v4

1 solution

Can you verify your connection string is correct, also make sure before calling ExecuteReader you open the DB connection.
 
Share this answer
 
Comments
Aswin_kumar 15-Apr-15 3:14am    
Thanks for your reply. I have added the Connection string. There is no mismatch in the connection String. I have also added the error message.

I am not sure why its throwing error in ServerVersion.

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