1

I have got a problem with connection with MySQL Database. I got MySQLData.dll. My connection string looks like that:

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

I have got OVH server. I think server name is a problem. I'm getting the following error:

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
Sudhakar Tillapudi
  • 25,935
  • 5
  • 37
  • 67
AdamLato
  • 47
  • 2
  • 13

4 Answers4

2
  • Add ProviderName=MySql.Data.MySqlClient to your connection string
  • Add reference MySQL.Data to your project

Additional troubleshooting, Make sure about the following:

  1. database started and accepting queries.
  2. Can you connect to the database locally on the database server?
  3. Do you have a firewall between the web server and the database server or are they on the same machine?

More Help on the following reference: http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL

Filburt
  • 17,626
  • 12
  • 64
  • 115
Adel
  • 1,468
  • 15
  • 18
  • 2.I can't, database on server what i bought 3.I don't think so FW is a problem. – AdamLato Feb 16 '14 at 09:36
  • Before to go to the code part, you should make sure that you can connect to the database and that server is reachable first... please try install toad for mysql, you can download it from here http://www.quest.com/toad-for-mysql/ , try to connect to that server, if you couldn't then you have to solve the network issue before to try it in C# – Adel Feb 16 '14 at 09:41
  • It is reachable, because before i write page on PHP and every thing works fine, only when i try write at ASP.Net it doesn't work. – AdamLato Feb 16 '14 at 09:47
  • 1
    Sometimes if you add spaces or wrong connection string then this will give that result, could you please take the connection directly from the following formats in the page: http://www.connectionstrings.com/mysql-connector-net-mysqlconnection/ – Adel Feb 16 '14 at 09:51
  • @AdamLato To obtain a working connection string, maybe try out [using a Data Link Wizard](http://stackoverflow.com/a/10480011/205233). – Filburt Feb 16 '14 at 10:21
0

You are missing provider name. please try this one

String sCON = "Data Source=mysql51-105.perso; Initial Catalog=adamlato;  User Id=name; Password=pass;";
Aftab Ahmed
  • 1,727
  • 11
  • 15
  • Nope still doesn't work :/ System.ArgumentException: Keyword not supported. Parameter name: providername at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.GetOption(String key) at MySql.Data.MySqlClient.MySqlConnectionStringBuilder.set_Item(String keyword, Object value) at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnectionStringBuilder..ctor(String connStr) at MySql.Data.MySqlClient.MySqlConnection.set_ConnectionString(String value) at MySql.Data.MySqlClient.MySqlConnection..ctor – AdamLato Feb 16 '14 at 09:29
  • could you please use your connection string in web/app.config and then read it from there. – Aftab Ahmed Feb 16 '14 at 09:32
  • as i see in your connection string might be your server/DB/Username and password are incorrect. May be spelled wrong or you are missing upper or lower case. please check it again. – Aftab Ahmed Feb 16 '14 at 09:36
  • nope pass,login and database is right, I cheacked it twice. There is a problem with a server. – AdamLato Feb 16 '14 at 09:43
  • try to ping your server or try to connect with your database server with Navicat or something like that if server is reachable after that try to fix connection string. – Aftab Ahmed Feb 16 '14 at 09:45
  • It is reachable, because before i write page on PHP and every thing works fine, only when i try write at ASP.Net it doesn't work – AdamLato Feb 16 '14 at 09:52
  • String sCON = "Data Source=mysql51-105.perso; Initial Catalog=adamlato; User Id=name; Password=pass;"; try this – Aftab Ahmed Feb 16 '14 at 09:53
0

This error commonly occurs if the connection string isn't specified correctly.

For those coming from a SqlServer background, note that MySql's connection string is very different:

  • providerName="MySql.Data.MySqlClient" in place of providerName="System.Data.SqlClient"

For the connectionString= settings:

  • Server=Host.Name.com (or IP) - (same, but no :Port suffix)
  • Port=nnnn - default to 3306
  • DataBase=MyDatabase. Not Initial Catalog
  • Uid= or User Id= (same)
  • Pwd= or Password= (same)
  • Add Charset=utf8 if you require Unicode Support (e.g. if your Unicode chars are stored as ????)
StuartLC
  • 104,537
  • 17
  • 209
  • 285
0

try modifying your machine.config file to include the present connectionstring alongside the default sqlExpress connectionString. Also make sure your actual connectionstring in your code doesn't contain the port details. Worked for me...