What's the best way to use C # with mysql without using odbc

I need to access mysql database from C # code, but I'd rather not use ODBC for the reasons below.

I need to create a demo and I am using xampp on a USB stick. My code (database read / write code) is written in C #. So to keep the USB stick isolated from the computer running the demo, I am moving away from ODBC because of the installation reasons.

+1


source to share


4 answers


http://dev.mysql.com/downloads/connector/net/5.2.html



Last time I tried it, it worked fine, but if you need to connect to MySQL and SQL Server for example, you will need to duplicate the code once with SqlConnection and another with MysqlConnection.

+6


source


You might want to use the MySQL.Net connector



+2


source


In the spirit of Object Relational Mappers, you can use NHibernate with the MyGeneration Code Generator to create both mappings and classes for which you need a data access layer. There are myriad examples available .

FWIW. Unless you have certain parts where speed is absolutely critical, an ORM like NHibernate will take care of the CRUD for you and all you have to worry about is optimizing the parts where you really need speed.

This helps your problem because you have the ease of creating a DAL (MyGeneration can look at your database and generate whatever you need) and you can worry about the business logic of your application. This takes your problem and removes the need for you to even worry about whether ODBC is being used.

+2


source


Depending on your needs, you can also look at an ORM like SubSonic . It works with MySQL and will give you both database independence and ease of development.

+1


source







All Articles