• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Connecting to MySQL

Please help me, I'm new to MySQL. I downloaded "MySQL 5.0.19" and the "mysql-connector-odbc-5.0.0-alpha-win32" - ODBC driver.


MySQL username - root
MySQL Password - 4dm1n

I created a DB with "MySQL Administrator"
DB Name - test
Table - name

In VB6

Form with one button, and the following code:

Private Sub Command1_Click()
    Dim cnn As ADODB.Connection
    Set cnn = New ADODB.Connection
    Dim rst As ADODB.Recordset
    Set rst = New ADODB.Recordset
    cnn.Open "server=DICK-NB;db=test;driver=MySQL ODBC 3.51 Driver;uid=root;pwd=4dm1n"
    Set rst = cnn.Execute("SELECT Count(*) As cnt FROM test.name")
    MsgBox rst("cnt")
    Set rst = Nothing
    Set cnn = Nothing
End Sub

I get the following Error:
Run-time error '-2147467259 (80004005)'
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

Please help me.

1 Solution
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
Hate to ask the obvious, but have you set up a DSN for server DICK-NB and used?

 cnn.Open "dsn=MyDSNNAME;db=test;driver=MySQL ODBC 3.51 Driver;uid=root;pwd=4dm1n"
Hi DickSwart6,
 I aint really got a comment that could help you mate other than you mayby shouldnt post your root password on the forum, any forum for that matter.

i found using WAMP(windows-apache-mysql-php) a handy tool - easy to set up and build databases with.

You can get it as an all in one installer - google it its freeware

good luck
DickSwart6Author Commented:
fredthered, is it nesasery to create a DNS to connect, can't I just use ADO?
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
It all depends on whether or not ADO can resolve the 'Server' part of your original syntax. Why not give the DSN method a blast and see if this makes any difference. If it does, then chances are that ADO cannot resolve the name DICK-NB to mean the physical MySQL server.
DickSwart6Author Commented:
Please don't laugh, I havn't tried DNS because I don't know how. Can you help me.
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
DSN = Data Source Name

If you're using a Windows variant, a DSN is a data source that you create using the ODBC Data Sources tool in the Control Panel (In Windows XP, this is located in the Administration Tools category).

1. Click the Start Button
2. Goto Settings
3. Click on Control Panel
4. Locate the Data Sources (ODBC) applet
5. Start applet and select either User DSN or System DSN tab (User DSN only available to currently logged on user, System DSN for any user using the computer)
6. Click the Add... button, which brings up the Create Data Source dialog.
7. Select your MySQL driver and configure it for your system. The Data Source Name is what is referred to as the DSN!

Hope this helps.
DickSwart6Author Commented:
If I create DNS and install my app on other PC on the network is there anythin I should do on there PC's to be able to see the DB?
John Mc HaleForensic Computer Examiner, Analyst/Programmer & Database ArchitectCommented:
Yes create a DSN on that computer as well, configured to 'see' your database(server). System DSN's are probably  best in a networked environment as they allow any user who can log on to the computer, to access the data source.

You shouldn't need to set up a DSN.  I think the problem is you are trying to use the 3.51 version of the ODBC driver in your connection string, but you have installed the 5.0.0 version.  I would recommend that you install the current production version of the driver (3.51.12).  I tested your connection string with that driver and it works.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now