0

I'm trying to connect aspx to a wamp database. Here's the database credentials:

Server: mysql_wampserver
user: sa
password: Passw0rd
computer: mypc
database: ProjetoUtilizadores

In my web.config i'm using the following:

<add key="cn" value="Server=localhost\mysql_wampserver;Database=ProjetoUtilizadores;User ID=sa;Password=Passw0rd;Trusted_Connection=False"/>

Whenever i try to connect i get the error "26 - Error Locating Server/Instance Specified" any help? Thank you.

NOTE: Firewall is currently disabled on the computer that i'm using either for VisualStudio or WAMP server.

EDIT: i tried with Server=localhost and Server=MY_IP and now i get Named Pipes Provider, error: 40 - Could not open a connection to SQL ServeR

Ângelo
  • 71
  • 2
  • 3
  • 12
  • instead of `localhost` have you tried specifying path of `mysqld`? may be that fix it. Also do have a look at: http://stackoverflow.com/questions/14801948/how-to-connect-to-mysql-using-c – Vedant Terkar Sep 06 '14 at 15:59
  • Greetings. Where can i find that path? – Ângelo Sep 06 '14 at 16:00
  • 1
    If the database is located on your PC then remove the mysql_wampserver part, if the database is located on a machine named mysql_wampserver remove the localhost part. Or use the IP address of the target machine. [See here examples of MySql connection strings](http://www.connectionstrings.com/mysql/) – Steve Sep 06 '14 at 16:06
  • now i'm getting error: 40 - could not open a connection to sql server – Ângelo Sep 06 '14 at 16:39
  • SQL Server or MySql? Please show the code that opens the connection. I have more than a feeling where the error is. – Steve Sep 06 '14 at 16:48
  • 1
    See the answer from @Steve below. At which point, your conn string would likely look like this `` – EdSF Sep 06 '14 at 18:34

1 Answers1

1

If you connect to a MySql Server you need to use the MySqlConnection class and, of course, the same MySql version of every other ADO.NET classes (MySqlCommand, MySqlDataReader, MySqlDataAdapter).

So your code should be something like this....

 using(MySqlConnection cnn = new MySqlConnection(GetConnectionStringFromConfig()))
 {
     using(MySqlCommand cmd = new MySqlCommand(commandText, cnn))
     {
         cnn.Open();
         .......
     }
 }

These classes are available in the MySql .Net Connector.
The latest version could be downloaded here, after installation you need to add a reference to this library and add a using MySql.Data.MySqlClient; directive to your project files where you use these classes.

Steve
  • 213,761
  • 22
  • 232
  • 286