Coding Thread, vbs to write to mySQL on remote computer in Coding and Web Development; Hi guys having a little trouble connecting to a database i have moved from access to mySQL.
When a user ...
-
17th December 2007, 04:08 PM #1 vbs to write to mySQL on remote computer
Hi guys having a little trouble connecting to a database i have moved from access to mySQL.
When a user logs on I want to add an entry to the database via a vbs executed on the client PC. I used to do this with VBS & Access no problems but i'm scratching my head with VBS & mySQL.
So.. how would i open a connection to the "logons" table in the following example?
The myODBC name is "MYTEST" and the database is called "LOGONTEST" and they live on a server called "DBSVR1"
-
-
IDG Tech News
-
17th December 2007, 09:02 PM #2
- Rep Power
- 13
Re: vbs to write to mySQL on remote computer
Dim mysql, adocon
mysql = "Driver={MySQL ODBC 3.51 Driver}; Server=DBSVR1; Database=LOGONTEST; UID=<MyUser>; PWD=<MyPWD>"
Set adocon = CreateObject("ADODB.Connection")
#--- Run query
adocon.Open MyQuery, mysql
#--- update something?
adocon.Open mysql
adocon.ExecuteQuery(MyQuery)
adocon.close
Possibly. I'm not 100% if it's correct, I've just blagged that out of an ASP.NET VB project I'm working on.
I'm pretty sure they are similar. I may have some commands wrong. Google knows all if I am.
(One day I'll be better than Google... but until then...)
-
-
18th December 2007, 02:56 PM #3 Re: vbs to write to mySQL on remote computer
We use a MySQL database for recording logons. We record the computer and username details to a table. Assuming that your logons table has two fields called computer and user; the following should work (it's been edited from my own script, but I'm pretty sure it's correct).
Option Explicit
Dim WshNetwork
Dim strComputer
Dim strUser
Dim objDB
Dim objDBConn
Set WshNetwork = WScript.CreateObject("WScript.Network")
' GET COMPUTER AND USERNAME
strComputer = WshNetwork.ComputerName
strUser = WshNetwork.UserName
Set objDB = CreateObject("ADODB.Connection")
objDBConn = "driver={MySQL ODBC 3.51 Driver};server=DBSVR1;database=LOGONTEST;Uid=<USER _NAME>;Pwd=<PASSWORD>"
' OPEN CONNECTION TO DATABASE
objDB.Open objDBConn
Dim strSQL
strSQL = "INSERT INTO logons (computer, user)" & _
" VALUES ('" & strComputer & "','" & strUser & "')"
objDBConn.Execute strSQL
objDB.Close
Set WshNetwork = Nothing
Set objDB = Nothing
-
-
18th December 2007, 04:21 PM #4 Re: vbs to write to mySQL on remote computer
OK the nightmare is real
why it was'nt working was because you must have the myODBC driver on all clients :O OH NO!! (yes I know i could use group policy)
So i've changed the script to use (Microsoft.XMLHTTP) to do a silent post to a form on a webserver that has myODBC and a DSN connection to the database
talk about a pain in the A.
-
-
19th December 2007, 11:18 AM #5 Re: vbs to write to mySQL on remote computer
The MySQL ODBC driver comes as an msi and installs via group policy without any problems. Takes about 5 seconds.
-
SHARE: 
Similar Threads
-
By jkearns in forum Scripts
Replies: 6
Last Post: 23rd June 2007, 08:44 AM
-
By Mr_T in forum Educational IT Jobs
Replies: 7
Last Post: 21st May 2007, 08:10 PM
-
By Geoff in forum Windows Vista
Replies: 1
Last Post: 17th February 2007, 09:34 AM
-
By russdev in forum General EduGeek News/Announcements
Replies: 3
Last Post: 7th February 2007, 10:14 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules