MySQL DB Connection - VBScript [Updated]

Author Message
NssB

  • Total Posts : 31
  • Scores: 0
  • Reward points : 0
  • Joined: 6/26/2006
  • Status: offline
MySQL DB Connection - VBScript [Updated] Wednesday, July 19, 2006 6:11 PM (permalink)
0
Hi all,

Short piece of code this time demonstrating a MySQL connection with VBScript.
Script makes use of Local DSN.

Substitute your own DSN name in the DBConnect function. (objDB.open "portal")
And obviously substitute your own Table name ("SELECT * FROM martin")
 
[Update]:
I'd like to extend my thanks to ehvbs for his PM x2( it was quite long ;) - I was shown a more 'conventional' approach for extracting DB data.
Please review the following.
 


 '******************************************************************************************
 'Script Name: mysqltest.vbs 
 'Author: Martin Lydon
 'Created: 26/06/2006
 'Description: First attempt at MySQL Connection using local DSN - MySQL 3.51 ODBC Connector
 '******************************************************************************************
 'Script Initialisation
 
 OPTION EXPLICIT
 Dim objDB,arrRecord,strRecord,strOutput
 Dim oRS, nRec, oFld
 
 'Main Processing section
 'Database connection & select all from Table
 Set objDB = DBConnect()
 Set oRS = objDB.Execute("SELECT * FROM martin LIMIT 3")
 'Dump Records from Table
 WScript.Echo "Recordset Dump:"
 nRec = 0
 Do While Not oRS.EOF
    WScript.Echo "-----", nRec : nRec = nRec + 1
    For Each oFld In oRS.Fields
        WScript.Echo oFld.Name & " = " & oFld.Value
    Next
    oRS.MoveNext
 Loop
 
 'Procedures section
 'This function sets up DB Connection using specified DSN
    Function DBConnect
    Set objDB = CreateObject("ADODB.Connection")
    objDB.Open "portal"
    Set DBConnect = objDB
 End Function
 
  
 
 

<message edited by NssB on Thursday, July 20, 2006 11:07 PM>
Its all about the code!
 
#1
    buffi

    • Total Posts : 88
    • Scores: 0
    • Reward points : 0
    • Joined: 3/28/2005
    • Location:
    • Status: offline
    RE: MySQL DB Connection - VBScript [Updated] Wednesday, November 01, 2006 9:43 PM (permalink)
    0
    Hi All,
    Thanks for the script.  I tried to work with it but i am getting the following error.
    I have created the ODBC DSN connection and the user for the DB is sa with Null password.
    In the ODBC test everything is working fine. TEST SUCCESSFULL
    and when i try to run the script this is the error i get.
    Can anybody point me what am i doing wrong?
    I also need to now if there is a script that will create an automatic ODBC connection.
     
    Line 32
    Char 3
    Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user '(null)'. Reason: Not associated with a trusted SQL Server connection
    Code: 80040E4D
     
     
     
    Regards,
    Buff
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9