我遇到了与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
答案 0 :(得分:2)
ProviderName=MySql.Data.MySqlClient
添加到您的连接字符串MySQL.Data
添加到您的项目其他疑难解答,请确保以下内容:
以下参考资料的更多帮助: http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL
答案 1 :(得分:0)
您缺少提供商名称。请尝试这个
String sCON = "Data Source=mysql51-105.perso; Initial Catalog=adamlato; User Id=name; Password=pass;";
答案 2 :(得分:0)
如果未正确指定连接字符串,则通常会发生此错误。
对于来自SqlServer
背景的人,请注意MySql
的连接字符串非常不同:
providerName="MySql.Data.MySqlClient"
代替providerName="System.Data.SqlClient"
对于connectionString=
设置:
Server=Host.Name.com
(或IP) - (相同但没有:Port
后缀)Port=nnnn
- 默认为3306
DataBase=MyDatabase
。不是Initial Catalog
Uid=
或User Id=
(相同)Pwd=
或Password=
(相同)Charset=utf8
(例如,如果您的Unicode字符存储为????)答案 3 :(得分:0)
尝试修改machine.config文件以包含当前的连接字符串以及默认的sqlExpress connectionString。还要确保代码中的实际连接字符串不包含端口详细信息。为我工作......