SqlConnection not being able to open the connection

What I have

  1. An account in http://www.freesqldatabase.com
  2. A database (DB_DATABASE var in my asp.net application)
  3. An user and password for the DB (DB_USER, DB_PASS)
  4. An Host URL (sql4.freesqldatabase.com [DB_SERVER])
  5. A catalog, plus three tables (DB_CATALOG)
  6. A port (DB_PORT)

What I aim

To connect from my asp.net app, to my database.

What have I tried

I tried to build a SqlConnection, just like:

SqlConnection con = new SqlConnection(@"Data Source=(" + DB_SERVER + "\" + DB_DATABASE + "," + DB_PORT + ");Initial Catalog=" + DB_CATALOG + ";UID=" + DB_USER + ";PWD=" + DB_PASS + ";");

I’ve used DB_DATABASE as the instance name, but I’m not sure about that (any explanation to clarify me this mess would be apreciated!)

But I’ve also tried without it:

SqlConnection con = new SqlConnection(@"Data Source=(" + DB_SERVER + "," + DB_PORT + ");Initial Catalog=" + DB_CATALOG + ";UID=" + DB_USER + ";PWD=" + DB_PASS + ";");

And several options besides these ones, trying to modify the connection string, but no one has worked yet =(

What I obtain

Well, when I’m trying to open the connection, I’m getting the following exception (I’ve tried to look for any useful data here, but I’m not used to this yet…):

   en System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   en System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   en System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
   en System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   en System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   en System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   en System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData)
   en System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   en System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   en System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   en System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   en System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   en System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   en System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   en System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   en System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   en System.Data.SqlClient.SqlConnection.Open()
   en Gallery.Gallery.registerNewUser(String username, String encripted_password)

Plus, Found out

At http://www.freesqldatabase.com/category/net/ , they said they’ve said:

Due to a bug within some MySQL connectors, the ‘Out of sync with server’ error is returned.

To resolve this, use a different version of the MySQL connector.

But since I’ve seen nothing about this in the exception stacktrace, I’m not sure if I’m being affected by this (plus it’s 2011 news).

Did I do something wrong when building the connection? How can I fix it?

Thank you in advance!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

All objects starting with “Sql” such as “SqlConnection”, “SqlCommand”, etc. are made for SQL Server. Apparently you are using MySQL so you need a different provider: https://dev.mysql.com/downloads/connector/net/

Once you add this provider as a reference in your project, you will be able to use “MySqlConnection”, “MySqlCommand”, etc.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x