#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    Connecting to mysql server


    Hopefully this is the right place...

    I have an HTA application that runs on the desktop. So far it works really well. Recently I was wondering if it was possible to connect to a mysql server that is running on my computer? If so... how do I go about connecting and using the database via HTA/vbscript? Or does someone have another suggest that would work? I'm flexible!
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,453
    Rep Power
    4539
    Unless something has changed in recent years, you need to visit the mysql site and download the mysql ODBC drivers. Then as long as you have no firewall blocking the path to your mysql server you can create an ADO connection to the mysql database.

    Google will find you plenty of examples of using ADO with VB and VBScript. There are some VB examples in the myodbc documentation too.
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Doug,

    Thanks for the help! I did find some great examples but I'm still a bit stuck. I followed several of the examples but for some reason I'm getting an error message.

    I'm running MySQL 5.5
    I have Connector ODBC 5.2 installed

    I have no problems connecting and using the MySQL server from the command prompt... but I just cannot figure out a working ADO connection that will work via vbscript.

    The latest example is:
    SQL = "SELECT * FROM master"
    ConnString = "Server=localhost; Database=catalog; User=loop; Password=loopy;"
    Set Connection = CreateObject("ADODB.Connection")
    Set Recordset = CreateObject("ADODB.Recordset")
    Connection.Open ConnString

    If I try and connect I get the following error:
    [Microsoft][ODBC Driver Manager] Data Source Name Not Found and No Default Driver Specified

    Any thoughts?
  6. #4
  7. Humble Learner
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Location
    Bangalore, India
    Posts
    280
    Rep Power
    120
    Try creating a DSN for connection to MySql
    Use the DSN in the connection string.
    http://folding.extremeoverclocking.com/user_summary.php?s=&u=472288
  8. #5
  9. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,453
    Rep Power
    4539
    Your connection string is wrong. Here's an example for MyODBC 5.1 but you may need to check for what to use with 5.2

    http://www.connectionstrings.com/mys...ctor-odbc-3-51
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0
    Okay... I corrected the string but it still wouldn't work. I tried the DNS and well... it worked but didn't.

    If I put the connection string for the DNS in a stand alone VBS file it works fine.

    If I include the VBS file as part of the HTA application it gives the above error.

    Is there something special about HTA's that might be preventing it from accessing the DNS connection?

    PS: Thank y'all for your patience in helping with this!
  12. #7
  13. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,453
    Rep Power
    4539
    What is an HTA application? Is that some part of visual basic, and if so what version of VB includes it?
    ======
    Doug G
    ======
    Bartender to Rene Descartes "have another beer?" Descartes: "I think not" and he vanished.
    --Alfred Bester
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    14
    Rep Power
    0
    You can simply use

    Public cnnConection As ADODB.Connection

    Set cnnConection = New ADODB.Connection
    With cnnConection
    .Open "Provider=SQLNCLI10;Server=USER\SQLEXPRESS;Database=Name;Trusted_Connection=yes; Encrypt=yes"

    Easy and simple ....

IMN logo majestic logo threadwatch logo seochat tools logo