Monday, 15 June 2015

c# - InvalidOperationException on SqlConnection.Open -



c# - InvalidOperationException on SqlConnection.Open -

i'm designing little irc bot used game in chat.

the source, programme , sql connection details never available public, i'm not worried security.

my connection string follows:

"server=sql.mydomain.com,3306;database=sqldatabasename;user id=sqlusername;password=sqlpassword;"

needless say, have obfuscated details here. after googling around , finding http://www.developerfusion.com/tools/sql-connection-string/ used generate string:

"data source=sql.mydomain.com,3306;initial catalog=sqldatabasename;integrated security=false;user id=sqlusername;password=sqlpassword;"

in both instances, trying open connection next code:

using (var sql = new sqlconnection(connectionstring)) { sql.open(); //sql operations here }

however i'm receiving invalidoperationexception on sql.open() every time. absolutely details i'm putting connection string correct, , based on found on google, cause of exception seems connection string, i'm not sure i'm doing wrong.

edit: message of exception "internal connection fatal error." according msdn, invalidoperationexception on sqlconnection.open can mean 1 of 2 things: either no server or info source provided in connection string or connection open.

i'm assuming first can trigger if server or info source invalid somehow, i've tried opening with:

if (sql.state != connectionstate.open) sql.open();

and still receive error.

did searching, , string seems perfect. changed string yours , worked here. thing find this, not know if helps or bot(worth try).

"data source=tcp:sql.mydomain.com,3306;initial catalog=sqldatabasename;integrated security=false;user id=sqlusername;password=sqlpassword;"

saw on this site again, not know if changes anything.

hope helps

c# sql

No comments:

Post a Comment