Database Connection

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
jtsy
Newbie
Posts: 7
Joined: Tue Jul 17, 2007 9:09 am

Database Connection

Post by jtsy » Tue Jul 17, 2007 9:15 am

Hi i'm trying to connect to MySQL Database using ODBC Connection Driver. There was no error message when i executed it, but my database doesn't seem to be updated. Any form of help will be greatly appreciated! Below is my code

Dim MyDB : MyDB=Server.CreateObject("ADODB.Connection")

MyDB.open "Driver={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=mydatabase; USER=root; PASSWORD=*****; OPTION=3;"

MyDB.Execute("INSERT INTO carriertest VALUES('3', 'temp');")

Thank you very much :D

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jul 17, 2007 9:26 am

The value returned by the Execute function should give you some clues.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jtsy
Newbie
Posts: 7
Joined: Tue Jul 17, 2007 9:09 am

Post by jtsy » Tue Jul 17, 2007 9:49 am

Erm how do you check what value is actually taken in? How do we print out the value? Sorry I'm a total newbie :P

After changing the final line to

Set rs = MyDB.Execute("INSERT INTO carriertest VALUES('3', 'temp');")

I now get an error message

Specified Window "rs = MyDB.Execute("INSERT INTO carriertest VALUES('3', 'temp');")" Not Present, Any subsequent key sends in script may cause exceptions.

Thanks for your help

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jul 17, 2007 9:52 am

The code you provided is VBScript. So it should appear in a VBScript block. Something like:

VBSTART
Dim MyDB
Dim rs

Set MyDB = Server.CreateObject("ADODB.Connection")

MyDB.open "Driver={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=mydatabase; USER=root; PASSWORD=*****; OPTION=3;"

Set rs = MyDB.Execute("INSERT INTO carriertest VALUES('3', 'temp');")
VBEND
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jtsy
Newbie
Posts: 7
Joined: Tue Jul 17, 2007 9:09 am

Post by jtsy » Tue Jul 17, 2007 10:21 am

It worked! Thanks!! :D

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts