Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends.
help me with this issue please.

I'm trying to connect to MySql using ASP.Net.
i'm using this code to do this:

C#
using System.Data;
using System.Data.Odbc;
//......
DataSet Mysql_ds = new DataSet();
OdbcConnection Mysql_con;

string Mysql_conStr = "Driver={MySQL ODBC 4.1 Driver};Server=SERVERNAME;Database=DBNAME;uid=USER;pwd=PASS";

Mysql_con = new OdbcConnection(Mysql_conStr);
Mysql_con.Open(); 
//....


this code works well when i use it in C#, WindowsFrom Application, BUT When I use this code in ASP.NET and upload it to my server, when i go to my website address, i get this error :

Exception Details: System.Data.Odbc.OdbcException: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

the error line is in the last line ( Mysql_con.open() ).

I have searched a lot and do some tries but nothing solved yet :(
How should I solve this problem!
OR
Is there any better way to create mysql connection !?

here is some information about the MySql installed on the server site :

localhost:
Server version: 4.1.22-community-nt
Protocol version: 10
Server: localhost via TCP/IP
User: USER@127.0.0.1

phpMyAdmin - 2.10.1:
MySQL client version: 5.0.45
Used PHP extensions: mysql
Posted
Updated 30-Aug-12 5:43am
v2

1 solution

You must add the odbc driver in your server. Administrative Tools --> ODBC.

ODBC isn't recommended. You mus read this and try to implement on your project:
http://bitdaddys.com/MySQL-ConnectorNet.html[^]

http://dev.mysql.com/downloads/connector/net/[^]

http://dev.mysql.com/doc/refman/5.0/en/connector-net.html[^]

Hope it helps.
 
Share this answer
 
Comments
Mohamad77 30-Aug-12 12:39pm    
I have create a new Website in visual studio,
then I go to website -> add reference... and add the MySql.Data.dll from installation folder.
now i have this ERROR message after uploading files to my server and then browse it:

Parser Error Message: Could not load file or assembly 'MySql.Data, Version=6.4.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified.

Line 40:<add assembly="MySql.Data, Version=6.4.5.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D">

so what should i do now?
thanks again
Christian Amado 30-Aug-12 13:16pm    
Right click on MySql.Data.dll --> Properties --> Set Local Copy to True. :)
Mohamad77 30-Aug-12 14:04pm    
sorry Christian,
I didn't create Web Application, I Create New Website in visual studio, and how could I access the specific reference properties in Website !? (NOT WebApplication)
thanks for reply
Mohamad77 1-Sep-12 3:11am    
WELL DONE.
THANKS ALOT.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900