2012-11-29 181 views
0

我想从c#应用程序使用SSL连接到MySQL。下面是我的连接字符串:SSL连接错误

server = "xxx.xxx.xxx.xxx"; 
     database = "sqlserver"; 
     uid = "sqlserver"; 
     password = "password"; 
     cert_file = "client-cert.pfx";  
     string connectionString; 
     connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + "; CertificateFile=" + cert_file + "; CertificatePassword=admin; SslMode=Required"; 

这是错误:

System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream. at System.Net.FixedSizeReader.ReadPacket(Byte[] buffer, Int32 offset, Int32 count) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) at MySql.Data.MySqlClient.NativeDriver.StartSSL() at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at

我认为这个问题是我的文件,但现在我知道这是不是...所以我失去了

+0

ssl证书是否指定主机名模式? –

+0

可能是这个问题 - http://www.limilabs.com/blog/received-unexpected-eof-0-bytes-from-transport-stream – Petesh

回答

0
server = "xxx.xxx.xxx.xxx"; 

大多数情况下,SSL证书定义了主机名模式(例如* .google.com)。在SSL认证期间,主机名被验证为来自正确的域。使用服务器的IP地址将导致此检查失败。

我会尝试将主机名设置为服务器,看看你是否得到不同的结果。

+0

我使用了主机名,但我仍然有这个错误。 – sedigo

+0

可能是我的openssl安装问题。我已经安装了从http://slproweb.com/products/Win32OpenSSL.html下载的64位OpenSSL。我是否还需要在Visual Studio中包含任何内容?这可能是问题吗? – sedigo