...

View Full Version : Connection String for Javascript



jtaylor
08-05-2004, 02:55 PM
Hello!

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

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!

sad69
08-06-2004, 12:43 AM
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.

Jeewhizz
08-06-2004, 12:50 AM
As mentioned - probably better in the ASP Forum...

Moving :)

Roy Sinclair
08-06-2004, 04:22 PM
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.

jtaylor
08-09-2004, 02:16 PM
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!

raf
08-09-2004, 02:52 PM
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");

angst
08-09-2004, 03:16 PM
this is the mysql connection string that i use with ASP,



<%
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"
%>

jtaylor
08-09-2004, 03:18 PM
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.

Roy Sinclair
08-09-2004, 07:29 PM
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.

raf
08-09-2004, 07:47 PM
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

http://www.codingforums.com/showthread.php?t=42157&highlight=asp+connection



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum