gpt4 book ai didi

c# - 无法从 ASP.NET 连接到 MySQL 数据库

转载 作者:行者123 更新时间:2023-11-29 06:40:34 26 4
gpt4 key购买 nike

我在连接 MySQL 数据库时遇到问题。我得到了 MySQLData.dll。我的连接字符串如下所示:

String sCON = "Server=mysql51-105.perso; Database=adamlato;  UID=name; Password=pass";

我有 OVH 服务器。我认为服务器名称是个问题。我收到以下错误:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
---> System.Net.Sockets.SocketException (0x80004005): Żądana nazwa jest prawidłowa, ale dane żądanego typu nie zostały znalezione
at System.Net.Dns.GetAddrInfo(String name)
at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)
at System.Net.Dns.GetHostEntry(String hostNameOrAddress)
at MySql.Data.Common.MyNetworkStream.GetHostEntry(String hostname)
at MySql.Data.Common.MyNetworkStream.CreateStream(MySqlConnectionStringBuilder settings, Boolean unix)
at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.NativeDriver.Open()
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 System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable)
at _Default.Page_Load(Object sender, EventArgs e)
in c:\Users\Adam\Documents\Visual Studio 2013\WebSites\WebSite2\Default.aspx.cs:line 20

最佳答案

  • ProviderName=MySql.Data.MySqlClient 添加到您的连接字符串
  • 将引用 MySQL.Data 添加到您的项目

其他故障排除,请确保以下内容:

  1. 数据库启动并接受查询。
  2. 你能连接到数据库服务器上的本地数据库吗?
  3. Web 服务器和数据库服务器之间是否有防火墙,或者它们是否在同一台机器上?

有关以下引用的更多帮助: http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL

关于c# - 无法从 ASP.NET 连接到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21809353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com