HSN Posted December 31, 2005 Posted December 31, 2005 Hiii there, I have never programmed a windows app which uses a db system. I'm a php + mySQL developer and I currently have a database on mySQL. I just wanna use this db using a C# program. Please give me the starting key for that. Thx Quote
HSN Posted December 31, 2005 Author Posted December 31, 2005 Here is my procedure for connecting to mysql: internal void mySQL() { string mySQLString = "DRIVER={MySQL};DATABASE=system;"; mySQLString += "SERVER=localhost;"; mySQLString += "UID=root;PWD=1234;"; System.Data.Odbc.OdbcConnection myDb = new OdbcConnection(mySQLString); try { myDb.Open(); } catch (System.Exception E) { MessageBox.Show(E.ToString()); } } while I get the following exception: ERROR [iM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Quote
TheWizardofInt Posted January 2, 2006 Posted January 2, 2006 Did you download the ODBC Driver from MySQL? This is the connection I use in VB.Net Dim sDSN As String Dim dt As New DataTable Dim da As OdbcDataAdapter Dim oConn As OdbcConnection Dim cmd As New OdbcCommand 'build the connection with parameters sDSN = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=<Server Name>;DATABASE=<Database Name>;UID=root;PASSWORD=;OPTION=3" Try 'connect to the inherent MySQL connection oConn = New OdbcConnection(sDSN) cmd.CommandText = sSql cmd.Connection = oConn cmd.CommandTimeout = 0 'allow for the timeout problem da = New OdbcDataAdapter(cmd) da.Fill(dt) Catch ex As Exception dt = Nothing Return dt End Try da.Dispose() oConn.Close() oConn.Dispose() Return dt Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
HSN Posted January 2, 2006 Author Posted January 2, 2006 In fact I haven't installed the ODBC. I'll try to install it now. Quote
HJB417 Posted January 2, 2006 Posted January 2, 2006 There's also a .net library MySQL Connector/Net enables developers to easily create .NET applications that require secure, high-performance data connectivity with MySQL. It implements the required ADO.NET interfaces and integrates into ADO.NET aware tools. Developers can build applications using their choice of .NET languages. MySQL Connector/Net is a fully-managed ADO.NET driver written in 100% pure C#. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.