C#Mysql连接问题 - 连接尝试失败

时间:2014-07-27 08:24:40

标签: c# mysql asp.net

加载C#ASP.net页面时出现以下错误。

  

连接尝试失败,因为连接方没有   在一段时间后正确回应,或建立连接   失败,因为连接的主机无法响应

     

[SocketException(0x274c):连接尝试失败,因为   连接方在一段时间后没有正确回应,或者   建立的连接失败,因为连接的主机失败了   响应] System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32   offset,Int32 size,SocketFlags socketFlags)+6528783   System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,   Int32尺寸)+130

     

[IOException:无法从传输连接中读取数据:A   连接尝试失败,因为连接方没有正确   一段时间后回复,或建立连接失败   因为连接的主机无法响应。]   System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,   Int32 size)+296 MySql.Data.Common.MyNetworkStream.Read(Byte []   buffer,Int32 offset,Int32 count)+47

     

[TimeoutException:无法从传输连接中读取数据:   连接尝试失败,因为连接方没有   在一段时间后正确回应,或建立连接   失败,因为连接的主机无法响应。]   MySql.Data.Common.MyNetworkStream.Read(Byte []缓冲区,Int32偏移量,   Int32计数)+204 MySql.Data.MySqlClient.TimedStream.Read(Byte []   缓冲区,Int32偏移量,Int32计数)+128   System.IO.BufferedStream.Read(Byte []数组,Int32偏移量,Int32计数)   +262 MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream,Byte [] buffer,Int32 offset,Int32 count)+42
  MySql.Data.MySqlClient.MySqlStream.LoadPacket()+64
  MySql.Data.MySqlClient.MySqlStream.ReadPacket()+32
  MySql.Data.MySqlClient.NativeDriver.Open()+253
  MySql.Data.MySqlClient.Driver.Open()+ 22
  MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder   设置)+208 MySql.Data.MySqlClient.MySqlConnection.Open()+625   UoRLive.iPadLayout.Page_Load(Object sender,EventArgs e)in   C:\用户\科尔宾   斯派塞\文档\ FinalYearProject \ UoRLive \ UoRLive \ iPadLayout.aspx.cs:92   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,   EventArgs e)+51 System.Web.UI.Control.OnLoad(EventArgs e)+92   System.Web.UI.Control.LoadRecursive()+54   System.Web.UI.Page.ProcessRequestMain(布尔   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)   772

背景:

当尝试连接到本地MYSQL数据库时,脚本在本地计算机上运行完美,但我已将其移至smarterasp.net,设置另一个MYSQL数据库,现在收到此错误消息。

唯一改变的是连接字符串:

public static string GetConnectionString()
    {


        string connStr = String.Format("server={0};user id={1}; password={2}; port={3};" +
                 "database=MYDATABASE_resources; pooling=false", "SQL5011.Smarterasp.net",
                 "DMYDATABSE_resources_admin", "MyPassword", "1433");


        return connStr;
    }

详细信息100%正确,我已通过使用MYsql工作台连接到服务器来检查它们。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

1433是默认的SQL Server端口。

3306是默认的MySQL端口。