SocketException:没有这样的主机是已知的
Posted
技术标签:
【中文标题】SocketException:没有这样的主机是已知的【英文标题】:SocketException : No such host is known 【发布时间】:2011-06-25 14:31:51 【问题描述】:我想从我的 ASP 页面连接到 mysql 数据库。因此,根据我的托管服务提供商所说,我使用了连接字符串,其中服务器被指定为“localhost:3309”
Dim myConnection As MySqlConnection = New MySqlConnection("server=localhost:3309; user id=TID; password=TPWD; database=TDB; pooling=false;")
Dim strSQL As String = "SELECT * from Device_Data"
Dim myDataAdapter As MySqlDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
Dim myDataSet As DataSet = New DataSet()
myDataAdapter.Fill(myDataSet, "Device_Data")
MySQLDataGrid.DataSource = myDataSet
MySQLDataGrid.DataBind()
但是当我运行这个页面时,我得到了这个错误
[SocketException (0x2af9): No such host is known]
System.Net.Dns.GetAddrInfo(String name) +6134386
System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6) +136
System.Net.Dns.GetHostEntry(String hostNameOrAddress) +109
MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname) +123
[Exception: Call to GetHostEntry failed after 00:00:02.2499197 while querying for hostname 'localhost:3309': SocketErrorCode=HostNotFound, ErrorCode=11001, NativeErrorCode=11001.]
MySql.Data.Common.StreamCreator.GetDnsHostEntry(String hostname) +405
MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout) +457
MySql.Data.MySqlClient.NativeDriver.Open() +215
[MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.]
MySql.Data.MySqlClient.NativeDriver.Open() +283
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) +51
MySql.Data.MySqlClient.MySqlConnection.Open() +362
System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +123
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +319
System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +92
show.form1_Load(Object sender, EventArgs e) in
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Control.LoadRecursive() +146
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
这是服务器问题吗?如果是,那么他们应该怎么做才能解决这个问题?当联系服务器人员时,他们说这是我的编码问题.. 他们是对的吗?
【问题讨论】:
【参考方案1】:试试server=localhost; port=3309
【讨论】:
【参考方案2】:The correct connection string for MySQL ADO.NET 连接器是
Server=localhost;Port=3309;Database=Test;Uid=username;Pwd=password;
【讨论】:
@Shijilal:很高兴它有帮助! :) 当我尝试将 E.F 连接到 MySql 时,它帮助了我。谢谢以上是关于SocketException:没有这样的主机是已知的的主要内容,如果未能解决你的问题,请参考以下文章
错误:DioError [DioErrorType.other]:SocketException:主机查找失败:未被捕获
Flutter SocketException:操作系统错误:没有到主机的路由,errno = 113,地址 = xxxx,端口 = 42376
.Net 核心 HttpClient 错误? SocketException:一个现有的连接被远程主机强行关闭
解决WCF大数据量传输 ,System.Net.Sockets.SocketException: 远程主机强迫关闭了一个现有的连接