VB.net and mySQL

Joined
Jun 22, 2004
Messages
5
Programming Experience
10+
I have tried many different tutorials trying to connect to a mySQL database from a windows application. None of them have worked. The most recent one is found at:

http://www.vbdotnetheaven.com/Code/Jun2003/2097.asp

When trying the code found on that page (and after changing everything to match my unique settings), I get the following error:

"An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in system.data.dll"

I have downloaded the MyOLEDB and newest version of the framework and everything else that the tutorials I have seen have suggested. If anyone knows a way to do this please help. I just want my program to grab information from my database and be able to delete records on occasion.

Thanks.

vs
 
try this one.
first install the odbc.net
VB.NET:
 imports microsoft.data.odbc
 dim cn as new odbcconnection(driver={mysql odbc 3.51 driver};database=temp)
 cn.open
 messagebox.show("connected")
hope it helps..
im also new about this thing...
 
Here is a way it is done with asp.net (vb.net ) with ODBC

1) MyODBC - MyODBC is a 32-bit ODBC Driver, also known as MySQL ODBC 3.51 Driver. After you have downloaded and installed MyODBC, you will need to setup a new DSN (Program Files > Administrator Tools > DataSource ODBC. Go to "System DSN" and click on "Add" Scroll down to MySQL ODBC 3.51 Driver and click on "Finish" (your not done yet though!)

Next enter the information for your MySQL Database, note Data Source Name is what you wish to call the DSN, for instance "mysqldsn". When finished click on "Test Data Source", if it connects, then click on ok, if not check your entries and try again.

2) ODBC .NET Data Provider - The Open Database Connectivity (ODBC) .NET Data Provider is an add-on component to the .NET Framework. It provides access to native ODBC drivers the same way the OLE DB .NET Data Provider provides access to native OLE DB providers.

After you have downloaded the exe, simply install and your done... go to step 3...

3) MDAC 2.7 - This may or may not be needed with your system, if your running Windows XP, then your ok, everyone else needs to download the new version...

Before you install MDAC 2.7, be sure to stop IIS and reboot after the install is complete...








OK There are a couple of key things to notice and remember here, the first is on line one in the Page Declaration. Notice the CompilerOptions='/R:"C:\Program Files\Microsoft.NET\Odbc.Net\Microsoft.Data.Odbc.dll"', this is needed in order for your application to find the odbc.net dll. Of course you can set this in your webconfig file but that's beyond the scope of this post...

The second important line to notice is: Import Namespace="Microsoft.Data.ODBC". You must import the Microsoft.Data.ODBC namespace in order for your application to use the ODBC objects...

Finally, on line number seven where we setup the dsn connection notice that the name "mysqldsn" is the same one I used as an example when setting up the dsn in step 2, be sure to change this to the name you entered when setting up your dsn...
 
Back
Top