1

I am trying to connect to my free sql database that I opened in: www.freesqldatabase.com/account/.

When using this www.phpmyadmin.co/ admin tool I can get into the databse, add tables and all that. But i can't connect to this database from my project. using this code:

SqlConnection sql = new SqlConnection("Server=sql7.freesqldatabase.com;Database=sql7115***;User Id=sql7115***;Password =*****;");
sql.Open();

I get an SqlException saying that "Could not find the server". Am I missing something?

By the way i am getting those warnings and if i click "here" i see this.

P.S: When i ping the host with the right port (that was sent to me with the email) I get a reply, so it is probably listening.

ChrisBint
  • 12,773
  • 6
  • 40
  • 62
cnc
  • 23
  • 8

2 Answers2

2

At the moment, the service you are using only offers MySql databases (though they intend offering MS SQL Server databases in the near future.

The problem is that the SqlConnection class you are using is deliberately tailored to MS Sql Server Databases, and - as I just said - that's not what you are talking to.

You will want to find an ADO.Net solution for MySQL - something like this.

Alternatively, you might be able to use OLEDB if you have suitable drivers installed...

Martin Milan
  • 6,346
  • 2
  • 32
  • 44
  • So i am using MySqlConnection and it is working! but is there a documentation for this API? I cant find it – cnc Apr 15 '16 at 10:48
  • You can find the [documentation](https://dev.mysql.com/doc/connector-net/en/) here. The [api documentation](https://dev.mysql.com/doc/connector-net/en/connector-net-ref.html) would be here. – Shamshiel Apr 15 '16 at 10:53
  • All the ADO.Net providers inherit from a common interface, meaning they work pretty much as you would expect... – Martin Milan Apr 18 '16 at 08:51
  • Thanks! I finally got it to work.. Almost quit before I saw this awesome answer :) +1 – Momoro Jan 23 '20 at 04:33
2

You can use the NuGet Package MySql.Data. To use it in your project insert following in the Package Manager Console.

Install-Package MySql.Data

After that you can use the class MySqlConnection. Don't forget to include the reference in your class!

using MySql.Data;
using MySql.Data.MySqlClient;

You should be able to establish a connection like this:

string connectionString = "server=sql7.freesqldatabase.com;user=sql7115***;database=sql7115***;password=******;";
MySqlConnection mySqlConnection= new MySqlConnection(connectionString);
mySqlConnection.Open();

For further information you can look in the tutorial.

Shamshiel
  • 2,051
  • 3
  • 31
  • 50