Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Apr 2004
    Location
    The Ghetto (Winchendon, MA)
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Connection String for Javascript

    Hello!

    I'm having a problem...obviously or I wouldn't be posting!

    Anyways, my problem is that I'm trying to connect to a MySQL database that is hosted by our web server host site. I want to connect to it using ASP pages and specifically using Javascript code. I've looked at thousands of examples of connection strings for both Javascript and VBScript but nothing has worked. I've tried setting up a system DSN and i've downloaded the latest ODBC driver (MySQL ODBC 3.51 Driver) for MySQL and the test connection works just fine but not in ASP.

    This is what I think it should look like using Javascript:

    <% @Language=Javascript %>

    <HTML>

    <HEAD>
    <%

    var conn = Server.CreateObject ("ADODB.Connection");
    conn.Open ("DRIVER={MySQL ODBC 3.51 Driver};SERVER=my_server;DATABASE=my_database;UID=my_uid;PWD=my_pwd");


    //just an aside here, i've tried using DRIVER={MySQL} instead of the above stated driver, didn't work. I've tried using the IP address and the actual host header for the server name and none have worked. I've tried changing the attribute PWD to PASSWORD and have added the attribute OPTION and PORT with the correct information but those haven't worked either...continuing on

    var sql = "SELECT * FROM my_table";

    var rs = Server.CreateObject ("ADODB.Recordset");
    rs.Open (sql,conn,1,3);

    Response.Write (rs.Recordcount);
    %>
    </HEAD>

    ...


    So, that's the basic setup I would use for any database connection whether it be for Access or for Excel, you would just change the connection string to suit the driver needs.

    I continuously receive this error whenever I try to run this script:

    Microsoft OLE DB Provider for ODBC Drivers error '80004005'

    [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

    /testMYSQL.asp, line 9

    ...


    Of course, this points straight to my connection string and explains that my driver is not correct or at least that's what I get out of it. So what am I doing wrong? I've made sure all my info is correct. I've made sure I have the correct access permissions to my database. I can connect to it directly from my website if I post the same script there but once I try to connect to it from my local machine using a IIS website it gives me that error everytime.

    Is there some standard connection string for this or am I attempting the impossible? Any help would be greatly appreciated.

    Thanks all!
    JT

  • #2
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know anything about ASP, but it looks like this is an ASP question, so it might get more of a response in the ASP forums.

    Sadiq.

  • #3
    Regular Coder
    Join Date
    May 2002
    Location
    London, England
    Posts
    369
    Thanks
    0
    Thanked 0 Times in 0 Posts
    As mentioned - probably better in the ASP Forum...

    Moving
    Jeewhizz - MySQL Moderator
    http://www.sitehq.co.uk
    PHP and MySQL Hosting

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Have you checked to find out if the driver for MYSQL is even installed? Without the driver being present, no amount of work with the connection string will ever make it happen.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #5
    New Coder
    Join Date
    Apr 2004
    Location
    The Ghetto (Winchendon, MA)
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not to be a dink about it but in the first paragraph that I wrote I stated that:

    i've downloaded the latest ODBC driver (MySQL ODBC 3.51 Driver) for MySQL and the test connection works just fine but not in ASP.

    So to answer your question, yes i've installed the driver. Trust me, i'm not that stupid!
    JT

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, never used javascript as scriptinglannguage forASP, but if i compaire it to my connectionstrings fro vbscript, then i'dsay that your attributesare in the wrong order. Maybe try it like

    conn.Open ("Driver=MySQL ODBC 3.51;server=my_server;user id=my_uid;password=my_pwd;database=my_database");
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #7
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    this is the mysql connection string that i use with ASP,

    Code:
    <%
      Dim MyConn
      Set myconn = Server.CreateObject("ADODB.Connection")
      MyConn.Open "Driver={mySQL};" & _
               "Server=192.168.0.5;" & _
               "Port=3306;" & _
               "Option=131072;" & _
               "Stmt=;" & _
               "Database=DataBaseName;" & _
               "Uid=sqlUser;" & _
               "Pwd=sqlPass"
    %>

  • #8
    New Coder
    Join Date
    Apr 2004
    Location
    The Ghetto (Winchendon, MA)
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    raf,

    Tried your suggestion but still no luck. Maybe i'll try using vbscript instead since i'm obviously not having any luck with javascript. Would you mind giving me some example code that you would use for vb? I would greatly appreciate it if you could. Thanks for your help so far.
    JT

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry about asking a question that already had an answer. The language you're scripting in should have no bearing whatsoever on the connection string though so switching to VBScript probably isn't going to do much more than confirm that you're not getting a connection. I suspect this is more of a permissions type of problem, look at what the account IIS is running under on your machine is capable of doing, if it can't access the database then that would be the real problem since the error message can be quite misleading.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #10
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jtaylor
    raf,

    Tried your suggestion but still no luck. Maybe i'll try using vbscript instead since i'm obviously not having any luck with javascript. Would you mind giving me some example code that you would use for vb? I would greatly appreciate it if you could. Thanks for your help so far.
    I've used the dns-less ones so they should work

    Moving from MS Access to MySQL
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •