Trouble connecting Visual Studio to MySQL

I have the MySQL connector and I can see my MySQL database in the server explorer, I'm able to create tables and stuff... but when I try to access it through SqlConnection or SqlCeConnection I get error 40 or the one in the image

enter image description here

In English it means error while trying to access object reference data not defined to an instance of an object.

Upvotes: 1

Views: 108

Answers (3)

can you please add Mysql.Data.MysqlClient; before that add reference to the source "Mysql.Data","Mysql.Web" Change "MySqlConnection" instead of "SqlConnection".

Upvotes: 1

Anirudha Gupta
Anirudha Gupta

Reputation: 9279

You are trying to use SqlConnection to connect MySql. This will not work this way. You need a Mysql.Data Library to use MySql Database.

Simply Every Sql (kind of class and method) prefix with 'My'. Like SqlConnection to MySqlConnection.

Upvotes: 1

marc_s
marc_s

Reputation: 754240

Well:

  • SqlConnection is for Microsoft SQL Server only
  • SqlCeConnection is for Microsoft SQL Server CE (Compact Edition) only

You need to use the MySqlConnection to connect to MySQL !

Upvotes: 1

Related Questions