PelicanDev
asked on
How to connect asp.net to mysql
Hi,
I tried to connect to a MySql data base with asp.net. It work fine on my dev machine but when i publish my web site on the server i got this message... I installed the odbc 3.51 driver on the server.
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
[OdbcException (0x80131937): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified]
System.Data.Odbc.OdbcConne ction.Hand leError(Od bcHandle hrHandle, RetCode retcode) +1156770
System.Data.Odbc.OdbcConne ctionHandl e..ctor(Od bcConnecti on connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle) +95
System.Data.Odbc.OdbcConne ctionOpen. .ctor(Odbc Connection outerConnection, OdbcConnectionString connectionOptions) +53
System.Data.Odbc.OdbcConne ctionFacto ry.CreateC onnection( DbConnecti onOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +55
System.Data.ProviderBase.D bConnectio nFactory.C reateNonPo oledConnec tion(DbCon nection owningConnection, DbConnectionPoolGroup poolGroup) +29
System.Data.ProviderBase.D bConnectio nFactory.G etConnecti on(DbConne ction owningConnection) +4863644
System.Data.ProviderBase.D bConnectio nClosed.Op enConnecti on(DbConne ction outerConnection, DbConnectionFactory connectionFactory) +117
System.Data.Odbc.OdbcConne ction.Open () +40
website_dealer.ViewSearchC lient_Acti vate(Objec t sender, EventArgs e) +100
System.Web.UI.WebControls. View.OnAct ivate(Even tArgs e) +111
System.Web.UI.WebControls. MultiView. set_Active ViewIndex( Int32 value) +398
System.Web.UI.WebControls. MultiView. OnInit(Eve ntArgs e) +49
System.Web.UI.Control.Init Recursive( Control namingContainer) +333
System.Web.UI.Control.Init Recursive( Control namingContainer) +210
System.Web.UI.Control.Init Recursive( Control namingContainer) +210
System.Web.UI.Control.Init Recursive( Control namingContainer) +210
System.Web.UI.Control.Init Recursive( Control namingContainer) +210
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +378
I tried to connect to a MySql data base with asp.net. It work fine on my dev machine but when i publish my web site on the server i got this message... I installed the odbc 3.51 driver on the server.
ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
[OdbcException (0x80131937): ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified]
System.Data.Odbc.OdbcConne
System.Data.Odbc.OdbcConne
System.Data.Odbc.OdbcConne
System.Data.Odbc.OdbcConne
System.Data.ProviderBase.D
System.Data.ProviderBase.D
System.Data.ProviderBase.D
System.Data.Odbc.OdbcConne
website_dealer.ViewSearchC
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Control.Init
System.Web.UI.Control.Init
System.Web.UI.Control.Init
System.Web.UI.Control.Init
System.Web.UI.Control.Init
System.Web.UI.Page.Process
string ConnStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=XXX;DATABASE=XXX;UID=XXX;PASSWORD=XXX;PORT=3306;OPTION=3;";
using (OdbcConnection con = new OdbcConnection(ConnStr))
{
using (OdbcCommand cmd = new OdbcCommand("DELETE FROM succursales WHERE ID=?", con))
{
cmd.Parameters.AddWithValue("@customerId", customerId);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
ASKER
Yes, i have create a DSN Entry for MySql connector and when i try the test connection button it connect succefully.
I added the DSN=MyConnector name in the connection string but no success...
I added the DSN=MyConnector name in the connection string but no success...
string ConnStr = "DRIVER={MySQL ODBC 3.51 Driver};DSN=XXX;SERVER=XXX;DATABASE=XXX;UID=XXX;PASSWORD=XXX;PORT=3306;OPTION=3;";
Try to use w/o DSN
string ConnStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=XXX;DATABAS E=XXX;UID= XXX;PASSWO RD=XXX;POR T=3306;OPT ION=3;";
Bm Keshav
string ConnStr = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=XXX;DATABAS
Bm Keshav
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
which version of MySql are you using ? I hope you are using 5.1 thats why mysql odbc 3.51 driver is not working, its work upto 5.0 ver.
Bm Keshav
Bm Keshav
It's a two stage process:
install the driver, then add a user or system DSN "linked" to that driver. The User or system DSN will then have a "name" that you allocate to it, and it is this name that you can use in your code. Also make sure you configure the driver/dsn with your specific connection settings.