Reputation: 337
I'm trying to make a connection to a MySQL database in Visual Studio 2017. So far using the wizards and datasets to connect has worked perfectly fine, but trying to make a connection using only code produces this error:
Googling this error, predictably, brings up results geared towards people using SQL Server, which I am not. What am I missing here? I know for a fact that my database is up and running because every other feature of my program still works.
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["GenericDB.Properties.Settings.GenericDBConnectionString"].ToString()))
{
try
{
string query = "SELECT name, siteID FROM site";
SqlDataAdapter da = new SqlDataAdapter(query, conn);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds, "site");
cmbOrderReceiving.DisplayMember = "name";
cmbOrderReceiving.ValueMember = "siteID";
cmbOrderReceiving.DataSource = ds.Tables["site"];
}
Upvotes: 2
Views: 123
Reputation: 216293
You are using the classes from the Sql Client library and these classes works with Sql Server only. After installing the connector for MySql you should add the proper using directive to your code files
using MySql.Data.MySqlClient;
then change every reference to the SqlXXXX classes with MySqlXXXX ones
using (MySqlConnection conn = new MySqlConnection(.....))
{
try
{
string query = "SELECT name, siteID FROM site";
MySqlDataAdapter da = new MySqlDataAdapter(query, conn);
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds, "site");
cmbOrderReceiving.DisplayMember = "name";
cmbOrderReceiving.ValueMember = "siteID";
cmbOrderReceiving.DataSource = ds.Tables["site"];
}
}
Upvotes: 3