Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...