【发布时间】:2012-03-18 18:22:47
【问题描述】:
尝试连接到 MySQL,使用 fluent nhibernate 和 Mono... 并收到此错误:
TdsInternalException: Server does not exist or connection refused.
我知道我的 mysql 凭据可以工作,因为非 nhibernate 连接在创建表、读取数据等方面是成功的。它只会在我尝试使用 fluent nhibernate 连接时崩溃
这是mysql连接字符串:
Server=localhost,3306;Database=mydb;uid=theUser;pwd=thePassword
这是 Fluent Nhibernate 配置代码:
var configuration = Fluently.Configure();
configuration.Database(MySQLConfiguration.Standard
.ConnectionString(sqlConnectionStr));
// mappings
sessionFactory = configuration.Mappings... so on....
这是完整的错误:
[exec] !! An error has occurred. The error is:
[exec] FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
[exec]
[exec] ---> System.Data.SqlClient.SqlException: Server does not exist or connection refused. ---> Mono.Data.Tds.Protocol.TdsInternalException: Server does not exist or connection refused. ---> System.Net.Sockets.SocketException: Connection refused
[exec] at System.Net.Sockets.Socket+SocketAsyncResult.CheckIfThrowDelayedException () [0x00000] in <filename unknown>:0
[exec] at System.Net.Sockets.Socket.EndConnect (IAsyncResult result) [0x00000] in <filename unknown>:0
[exec] at Mono.Data.Tds.Protocol.TdsComm..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion) [0x00000] in <filename unknown>:0
[exec] --- End of inner exception stack trace ---
[exec] at Mono.Data.Tds.Protocol.TdsComm..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion) [0x00000] in <filename unknown>:0
[exec] at Mono.Data.Tds.Protocol.Tds..ctor (System.String dataSource, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion tdsVersion) [0x00000] in <filename unknown>:0
[exec] at Mono.Data.Tds.Protocol.Tds70..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout, TdsVersion version) [0x00000] in <filename unknown>:0
[exec] at Mono.Data.Tds.Protocol.Tds80..ctor (System.String server, Int32 port, Int32 packetSize, Int32 timeout) [0x00000] in <filename unknown>:0
[exec] at Mono.Data.Tds.Protocol.TdsConnectionPoolManager.CreateConnection (Mono.Data.Tds.Protocol.TdsConnectionInfo info) [0x00000] in <filename unknown>:0
[exec] at Mono.Data.Tds.Protocol.TdsConnectionPool.GetConnection () [0x00000] in <filename unknown>:0
[exec] at System.Data.SqlClient.SqlConnection.Open () [0x00000] in <filename unknown>:0
[exec] --- End of inner exception stack trace ---
[exec] at System.Data.SqlClient.SqlConnection.Open () [0x00000] in <filename unknown>:0
[exec] at NHibernate.Connection.DriverConnectionProvider.GetConnection () [0x00000] in <filename unknown>:0
[exec] --- End of inner exception stack trace ---
【问题讨论】:
-
这里使用 SqlConnection 似乎很奇怪 - 你确定你没有在某处使用 MS SQL 配置吗?
-
我在使用 TcpClient 时遇到了同样的异常。它会在 'await tcpClient.ConnectAsync(ip, port)' 处抛出此错误,但如果我在此语句之前引入 1s 延迟,则可以正常工作!
标签: mysql nhibernate mono fluent