的SqlConnection不能够打开连接 [英] SqlConnection not being able to open the connection

查看:108
本文介绍了的SqlConnection不能够打开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. http://www.freesqldatabase.com 的帐户

  2. 数据库( DB_DATABASE VAR在我的asp.net应用程序)

  3. 为DB的用户名和密码( DB_USER DB_PASS

  4. 一个主机URL(sql4.freesqldatabase.com [ DB_SERVER ])

  5. 系统目录,再加上三个表( DB_CATALOG

  6. 端口( DB_PORT

  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)

要从我的asp.net应用程序连接到我的数据库。

What I aim

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

我试图建立一个的SqlConnection ,就像:

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 + ";");

我用 DB_DATABASE 作为实例名称,但我不知道这一点(任何解释,以澄清我这个烂摊子将是preciated! )

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 =(

好吧,当我试图打开连接,我得到了以下异常(我试图寻找这里的任何有用的数据,但我不习惯这个尚未...):

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)

另外,发现了

http://www.freesqldatabase.com/category/net/ ,他们说他们曾经说过:

Plus, Found out

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

由于一些MySQL的连接器内的错误,则返回不同步服务器的错误。

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

要解决此问题,使用不同版本MySQL连接器的。

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

但因为我什么也没看见这个在异常堆栈跟踪,我不知道如果我被受此(再加上它的2011的消息)。

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?

感谢你在前进!

推荐答案

开始的SQL,如SqlConnection的,的SqlCommand等都是针对SQL Server进行的所有对象。显然,你正在使用MySQL,所以你需要不同的供应商: https://dev.mysql.com/下载/连接器/ NET /

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/

一旦你添加此提供者在你的项目的引用,你将能够使用的MySqlConnection,MySqlCommand的,等等。

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

这篇关于的SqlConnection不能够打开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆