+ Post New Thread
Results 1 to 5 of 5
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 ...
  1. #1
    ChrisP's Avatar
    Join Date
    Apr 2007
    Location
    norfolk
    Posts
    150
    Thank Post
    4
    Thanked 8 Times in 8 Posts
    Rep Power
    17

    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"

  2. #2

    Join Date
    Jul 2007
    Location
    Devon
    Posts
    233
    Thank Post
    8
    Thanked 9 Times in 8 Posts
    Rep Power
    16

    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...)

  3. #3
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Whittington, Lancashire
    Posts
    286
    Thank Post
    40
    Thanked 36 Times in 26 Posts
    Rep Power
    26

    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

  4. #4
    ChrisP's Avatar
    Join Date
    Apr 2007
    Location
    norfolk
    Posts
    150
    Thank Post
    4
    Thanked 8 Times in 8 Posts
    Rep Power
    17

    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.

  5. #5
    altecsole's Avatar
    Join Date
    Jun 2005
    Location
    Whittington, Lancashire
    Posts
    286
    Thank Post
    40
    Thanked 36 Times in 26 Posts
    Rep Power
    26

    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:
+ Post New Thread

Similar Threads

  1. Replies: 6
    Last Post: 23rd June 2007, 08:44 AM
  2. I need to write my own job spec anyone have one i can mod?
    By Mr_T in forum Educational IT Jobs
    Replies: 7
    Last Post: 21st May 2007, 08:10 PM
  3. Write code using speech recognition!
    By Geoff in forum Windows Vista
    Replies: 1
    Last Post: 17th February 2007, 09:34 AM
  4. Nice write up here
    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
  •