MySQL OleDbConnection

T

Tim Bücker

Hello.

I am trying to get a connection to MySQL using OleDb but it seems that I am
making something wrong.
I´ve found this source in the net but it doesn´t work for me:

System.Data.OleDb.OleDbConnection con;
con=new System.Data.OleDb.OleDbConnection("");
con.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test;";
con.Open();

Where can I set the path to my localhost where mySql is running?
Trying to put it in Data Source I get an exception - invalid filename
Is the provider ok? Don´t I need a username and password?

And how does the connection string look when I want to create my FIRST
database?
Can I then leave the Data Source empty?

Having less experience working with databases I am also thankful for any
good resource tips on the net.
Thanks to anyone who can help me out!

Desperate greetings,
Tim.
 
N

Nick Malik

This article should help
http://dev.mysql.com/tech-resources/articles/dotnet/

You need to install a driver that will provide MySQL data to the OLEDB
interface, which is used by .NET. I believe that there are drivers
available, and that the article above will point you to them.

The connection string you gave allows you to connect to a JET database
(read: Microsoft Access). It won't work for MySQL (as you've discovered).

Good luck,
--- Nick
 
T

Tim Bücker

Nick Malik said:

Thanks for answering! I´ve read this article but I hope that it is an older
one reading this line here:
"MySQL currently doesn't officially support MyOLEDB, so this solution will
not be discussed here."

If it is not an older one - is it correct that the only "official" way to
connect to mysql using C# is odbc right now?
(Not regarding ByteFX.Data & CoreLabs)
The connection string you gave allows you to connect to a JET database
(read: Microsoft Access). It won't work for MySQL (as you've discovered).

Ah, thanks. JET = Access; didn´t know that. Damn Copy & Paste, ... ;-)
Greetings,
Tim.
 
N

Nick Malik

not sure what it means to say that there's an Official way to use MySQL!

However, what's wrong with using ODBC for your provider, instead of OLEDB?
ODBC is a good solid interface. All the bad press came from really poorly
implemented drivers.

You can use an ODBC driver from .NET and there's an open source one
available (as listed in the article).

I do hope I'm being helpful.

--- Nick
 
T

Tom Shelton

Hello.

I am trying to get a connection to MySQL using OleDb but it seems that I am
making something wrong.
I´ve found this source in the net but it doesn´t work for me:

System.Data.OleDb.OleDbConnection con;
con=new System.Data.OleDb.OleDbConnection("");
con.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test;";
con.Open();

Where can I set the path to my localhost where mySql is running?
Trying to put it in Data Source I get an exception - invalid filename
Is the provider ok? Don´t I need a username and password?

And how does the connection string look when I want to create my FIRST
database?
Can I then leave the Data Source empty?

Having less experience working with databases I am also thankful for any
good resource tips on the net.
Thanks to anyone who can help me out!

Desperate greetings,
Tim.

Tim,

I was wondering - have you considered using the ByteFx MySQL data provider?
It has been adopted by the MySQL team as the official MySQL data provider
for .NET. I have used it (and am using it :) and so far it seems quite
robust and fast. The nice thing is that it was written entirely in C# -
and requires none of the MySQL client libraries to be installed. You can
download it at:

http://www.bytefx.com

Another advantage - it works equally well under Mono as it does under .NET
- in fact it ships as part of the Mono distribution.
 
T

Tim Bücker

Tim Bücker said:
I am trying to get a connection to MySQL using OleDb but it seems that I am
making something wrong.

A big thanks to both of you, Nick Malik and Tom Shelton. You´re help did
help me.
I think I will then use ODBC as provider because ByteFx is only a beta
version but perhaps I will try that provider later.
A switch between different providers should be possible too. Shouldn´t be
complicated for ByteFx as it implements all standard ADO.NET provider
interfaces...

Greetings,
Tim.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top