C# vs MySQL?!!!!!

HSN

Member
Joined
May 2, 2004
Messages
23
Hiii there,

I have never programmed a windows app which uses a db system. Im 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
 
Here is my procedure for connecting to mysql:


Code:
		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
 
Did you download the ODBC Driver from MySQL?

This is the connection I use in VB.Net

Code:
           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
 
Back
Top