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

Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 24, 2010, 11:15 PM EDT
because it will work with integrated security. your connectino string will help us to fix the problem easily
Deepthi Aravind53 reputationPosted Oct 24, 2010, 11:21 PM EDT
Manikavelu VelayuthamRank #413 · 6K reputationPosted Oct 24, 2010, 11:31 PM EDT
<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 Aravind53 reputationPosted Oct 25, 2010, 12:20 AM EDT
I already tried this.but its not working.
Suthish NairRank #92 · 22.8K reputationPosted Oct 25, 2010, 2:14 AM EDT
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.
ASWIN KUMAR17 reputationPosted Apr 15, 2015, 2:29 AM EDT
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.