Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access a mySQL Database from VB

Status
Not open for further replies.

stefanRusterholz

Programmer
Aug 24, 2001
19
0
0
CH
I'm still a newbie, so please explain stepwise ;-)

I got following problem: i need to access (on the local machine) a mysql database. I downloaded myODBC 2.50.38 from mysql.com ( but i couldn't get it run.

The old code which accesses an MS Access DB instead of the mySQL DB is the following:

Code:
Dim rs As ADODB.recordset
Dim connStr As String
Dim SQLquery As String

Set rs = New ADODB.recordset
connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\database.mdb"
SQLquery = "SELECT something FROM mytable"

rs.open SQLquery, connStr

As I understand VB, I just needed to change the connectionstring. But to what?

Thanks for helping!
Stefan
 
Hi

You need to access the database through a DSN (Data source name). You can create a DSN in the control panel.
Try and search for mysql at there a couple of good examples by Yusuf Incekara.

Sunaj
 
Hmm, I searched a while for it in vbcode.com, but I couldn't find it. Can you please tell me where this examples are located?

Stefan
 
I tried that but it told me it had found 0 results :-(
But luckily I found it somewhere else.

But thank you anyway!

Stefan
 
Hmmm, strange. I tried it again and now it presents me some results...
perhaps it was just a misstypo before :-/

Stefan
 
A good alternative to a DSN is to code the connection string. I would recommend this so that when you begin installing your app on different PCs, you will not have to set up the DSN on each machine. Try this for SQL Server:

dim cnConn as adodb.connection

set cnConn = createobject("adodb.connection")
cnconn.connectionstring = "Provider=SQLOLEDB.1;Persist Security Info=True;Data Source=YourServerName;User Id=SA;Initial Catalog=YourSQLDataBaseName"

cnconn.open
 
That annoying laughing face is not intentional. It should be: S-Q-L-O-L-E-D-B
 
Thank you too.
I did it indeed with coding the connectionstring:

Code:
dim connstr as string
connstr = "driver={MySQL};server=my.server.domain;uid=myname;pwd=mypassword;database=myDB;"

dim rs as adodb.recordset
set rs = new adodb.recordset
rs.open "SELECT something FROM myTable", connStr

That's it.
With DSN I had too many problems :)

Stefan
 
How does one(me) determine the domain name of my server? I created a database and a table and through Mysql.exe loaded 47,000 records into the database and select * from mytable works like a charm.

Now I am trying to use VB to connect to it. I like the SQLOLEDB alternative but I see that the connection string must connect to a "my.server.domain". What is that? How is Mysql setup for this and how does the VB app see it?

Is there any other software to install? Like SQLOLEDB?

Thanks
Scoots987
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top