Rex Logan
Rex Logan

Reputation: 27156

what is the best way to use c# with mysql without using odbc

I need to access a mysql database from c# code but I would prefer not to use ODBC for the reasons below.

I have to create a demo and I am using xampp on a USB drive. My code (database Read/Write code) is written in C#. So to keep the USB drive isolated from the computer that the demo runs on I am moving away from ODBC because of setup reasons.

Upvotes: 1

Views: 1541

Answers (4)

George Stocker
George Stocker

Reputation: 57917

In the vein of Object Relational Mappers, you can use NHibernate with MyGeneration Code Generator to generate both the mappings and classes you'd need to have a Data Access layer. There are a myriad of examples available.

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

This helps your issue because you have the ease of DAL creation (MyGeneration can look at your database and generate everything you need), and you can worry about the Business Logic of your application. It takes your problem and removes the need for you to even worry about whether ODBC is being used.

Upvotes: 2

Rob Prouse
Rob Prouse

Reputation: 22657

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

Upvotes: 1

Kibbee
Kibbee

Reputation: 66162

You'll probably want to use the MySQL .Net connector

Upvotes: 2

Vinko Vrsalovic
Vinko Vrsalovic

Reputation: 340496

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, for example, MySQL and SQL Server you'll need to duplicate the code once using SqlConnection and the other using MysqlConnection.

Upvotes: 6

Related Questions