Hi
I am trying to establish connection to remote sql server through my c# code.
This is working fine when i tried connect to local server.
private static string _ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionstring"].ToString();
SqlConnection _con = new SqlConnection(_ConnectionString );
if (_con.State == ConnectionState.Open)
{
_con.Close();
}
_con.Open();
Before executing _con.open,I m geting dis error
+ ServerVersion '_con.ServerVersion' threw an exception of type 'System.InvalidOperationException' string {System.InvalidOperationException}
Please help me .Its very urgent..
Regards
Deepthi
Loading
ASWIN KUMARPosted Apr 15, 2015, 6:29 AM
Hope you would resolved this issue, I am having a similar kind of issue with my application. can you please help me with solution to this.
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:
During debug I found the below error message in objConn
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.
Suthish NairPosted Oct 25, 2010, 6:14 AM
Drag and drop a dropdownlist to the page, click on DataSource property and try to connect to your DB and bind THE control.
You will get the actual connection string.
Deepthi AravindPosted Oct 25, 2010, 4:20 AM
I already tried this.but its not working.
Manikavelu VelayuthamPosted Oct 25, 2010, 3:31 AM
<appSettings/>
<connectionStrings>
<add name="connWebOrdering" connectionString="Data Source=HorizonDC02;Initial Catalog=test;Integrated Security=True" providerName="System.Data.SqlClient" />
connectionStrings>
because it works with integrated security. Just try this once and let me know if its still not works.
Deepthi AravindPosted Oct 25, 2010, 3:21 AM
Manikavelu VelayuthamPosted Oct 25, 2010, 3:15 AM
because it will work with integrated security. your connectino string will help us to fix the problem easily