error with javascript in ASP

A

andre

Hi,

Maybe not the right newsgroup, but it's an ASP problem, so ..

This ASP file works fine with VBscript:
<%
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=msdasql; driver={microsoft access driver (*.mdb)};
dbq=d:\access\newres.mdb")
sql="select dag, aantalu from daguur;"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql, objdc, 3, 3
rec=rs.recordcount
rs.movefirst
da=rs.Fields("dag").Value
aanu=rs.Fields("aantalu").Value
....
%>
But how to translate this in Javascript? I tried this but ger the error:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open
registry key 'Temporary (volatile) Jet DSN for process 0x4a8 Thread 0x6e8
DBC 0x227335c Jet'.
/respen/newres/testj.asp, line 4

<%@ language=javascript %>
<%
var objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=msdasql; driver={microsoft access driver (*.mdb)};
dbq=d:\access\newres.mdb")
sql="select dag, aantalu from daguur;"
var rs=Server.CreateObject("ADODB.Recordset")
rs.Open("sql, objdc, 3, 3")
rec=rs.recordcount
rs.movefirst
da=rs.Fields("dag").Value
aanu=rs.Fields("aantalu").Value
%>

Thanks
Andre
 
M

Martin Honnen

andre wrote:

Maybe not the right newsgroup, but it's an ASP problem, so ..

This ASP file works fine with VBscript:
<%
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=msdasql; driver={microsoft access driver (*.mdb)};
dbq=d:\access\newres.mdb")
sql="select dag, aantalu from daguur;"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql, objdc, 3, 3
rec=rs.recordcount
rs.movefirst
da=rs.Fields("dag").Value
aanu=rs.Fields("aantalu").Value
...
%>
But how to translate this in Javascript? I tried this but ger the error:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open
registry key 'Temporary (volatile) Jet DSN for process 0x4a8 Thread 0x6e8
DBC 0x227335c Jet'.
/respen/newres/testj.asp, line 4

<%@ language=javascript %>
<%
var objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=msdasql; driver={microsoft access driver (*.mdb)};
dbq=d:\access\newres.mdb")
sql="select dag, aantalu from daguur;"
var rs=Server.CreateObject("ADODB.Recordset")
rs.Open("sql, objdc, 3, 3")

You are passing a string argument to Open which is nonsense, you simply need
rs.Open(sql, objdc, 3, 3);
rec=rs.recordcount
rs.movefirst

Make that
rs.movefirst();
where maybe you even need different casing
 
B

Bob Barrows [MVP]

andre said:
Hi,

Maybe not the right newsgroup, but it's an ASP problem, so ..

This ASP file works fine with VBscript:
<%
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=msdasql; driver={microsoft access driver
(*.mdb)}; dbq=d:\access\newres.mdb")
sql="select dag, aantalu from daguur;"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql, objdc, 3, 3
rec=rs.recordcount
rs.movefirst
da=rs.Fields("dag").Value
aanu=rs.Fields("aantalu").Value
...
%>
But how to translate this in Javascript? I tried this but ger the
error: Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open
registry key 'Temporary (volatile) Jet DSN for process 0x4a8 Thread
0x6e8 DBC 0x227335c Jet'.
/respen/newres/testj.asp, line 4

Martin dealt with the problem in your rs.open line, but that does not
address this problem which is caused by your use of the msdasql provider
instead of the native Jet OLEDB provider. Your connection string should be:

"provider=Microsoft.Jet.OLEDB.4.0; Data Source =d:\access\newres.mdb"

If you think you really need to use the deprecated msdasql provider for some
reason, then check out this article:
http://www.aspfaq.com/show.asp?id=2009

which should lead you to this KB article:
http://support.microsoft.com/?kbid=315456

HTH,
Bob Barrows
 
A

andre

Thanks both for replying.
I change both things but now i get:
Microsoft JET Database Engine (0x80004005)
Not a valid file name.
/respen/newres/testj.asp, line 4

I went to the site you referenced, but could not find that error.
This works with VB, maybe the syntax is somewhere wrong for javascript?

Thanks again
Andre





Bob Barrows said:
andre said:
Hi,

Maybe not the right newsgroup, but it's an ASP problem, so ..

This ASP file works fine with VBscript:
<%
set objdc = Server.CreateObject("ADODB.Connection")
objdc.Open("provider=msdasql; driver={microsoft access driver
(*.mdb)}; dbq=d:\access\newres.mdb")
sql="select dag, aantalu from daguur;"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql, objdc, 3, 3
rec=rs.recordcount
rs.movefirst
da=rs.Fields("dag").Value
aanu=rs.Fields("aantalu").Value
...
%>
But how to translate this in Javascript? I tried this but ger the
error: Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Microsoft Access Driver]General error Unable to open
registry key 'Temporary (volatile) Jet DSN for process 0x4a8 Thread
0x6e8 DBC 0x227335c Jet'.
/respen/newres/testj.asp, line 4

Martin dealt with the problem in your rs.open line, but that does not
address this problem which is caused by your use of the msdasql provider
instead of the native Jet OLEDB provider. Your connection string should be:

"provider=Microsoft.Jet.OLEDB.4.0; Data Source =d:\access\newres.mdb"

If you think you really need to use the deprecated msdasql provider for some
reason, then check out this article:
http://www.aspfaq.com/show.asp?id=2009

which should lead you to this KB article:
http://support.microsoft.com/?kbid=315456

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
 
B

Bob Barrows [MVP]

This is likely to be a permissions issue (which is covered at the site to
which I linked.) ASP runs under the Internet Guest account
(IUSR_MachineName). This account needs to be granted Change permissions for
the folder containing the database file.

Bob Barrows
 
A

andre

Sorry, but it still doesn't work (same error).
All the permissions of that directory are set to 'everyone'. I added all
permissions for IUSR_.

If that was the problem, the same ASP file with VB wouldn't work either, or
am i wrong?
 
B

Bob Barrows [MVP]

It doesn't need to be set to everyone. It needs to be set for the IUSR
account. If d: is a mapped network drive, IUSR will not have permission to
"see" it.


VB does not run under the IUSR account, it runs under the account of the
person who launched the VB application. ASP is a "server" application - it
does not run under the account of the person who made the request to the ASP
page, unless ASP is set to impersonate a specific account.

In addition, if the IIS application is set to run under medium or higher
security, then it's the IWAM account, not the IUSR, that will need
permissions for that folder.
 
A

andre

Hi Bob,

I feel uncomfortable for your time, but there is still a problem somewhere.
I run IIS 5.0 on windows 2000 server (no domain). The directory containing
the Access file is on a NTFS file and i put all the permissions also to
IWAM. I put the Application Protection of IIS to low.
I even tried with another FAT32 disc, where it's not possible to set
permission. Nothing to do: always:
Microsoft JET Database Engine (0x80004005)
Not a valid file name.
It's crazy ...
Thanks anyway ...
 
R

Roland Hall

in message : <%
: set objdc = Server.CreateObject("ADODB.Connection")
: objdc.Open("provider=msdasql; driver={microsoft access driver (*.mdb)};
: dbq=d:\access\newres.mdb")
: sql="select dag, aantalu from daguur;"
: set rs=Server.CreateObject("ADODB.Recordset")
: rs.Open sql, objdc, 3, 3
: rec=rs.recordcount
: rs.movefirst
: da=rs.Fields("dag").Value
: aanu=rs.Fields("aantalu").Value
: ...
: %>

I'm not sure what the case is since I only use Javascript on the
clients-side but I see several potential problems and this is untested.

1. Provider
2. \\ Escaping paths
3. CreateObject vs ActiveXObject
4. rs.Fields.Item(...).Value
5. J(ava)Script is case-sensitive so some commands might need to be
modified.

<%@ Language="JScript" %>
<%
var objdc = new ActiveXObject("ADODB.Connection");
var connstr = "provider=Microsoft.Jet.OLEDB.4.0; Data Source
=d:\\access\\newres.mdb";
objdc.Open(connstr);
var sql = "select dag, aantalu from daguur";
var rs = new ActiveXObject("ADODB.Recordset");
rs.Open(sql, objdc, 3, 3);
var rec = rs.recordCount;
rs.moveFirst();
var da = rs.Fields.Item("dag").Value;
var aanu = rs.Fields.Item("aantalu").Value;
....
%>

HTH...

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 
B

Bob Barrows [MVP]

andre said:
Hi Bob,

I feel uncomfortable for your time, but there is still a problem
somewhere. I run IIS 5.0 on windows 2000 server (no domain). The
directory containing the Access file is on a NTFS file and i put all
the permissions also to IWAM. I put the Application Protection of IIS
to low.
I even tried with another FAT32 disc, where it's not possible to set
permission. Nothing to do: always:
Microsoft JET Database Engine (0x80004005)
Not a valid file name.
It's crazy ...
Thanks anyway ...

See Roland's reply. I think he's spotted the problem: I forgot you needed to
escape the backslashes in the path string in javascript. I should have
advised you to use response.write to verify that the connection string was
correct.

var sConnect = "Provider=...."
Response.Write(sConnect)

Bob Barrows
 
R

Roland Hall

in message : Thanks, it works now.
: The only thing i had to change was \\

Well, the only thing now, right? Hopefully you have already changed your
provider to OLEDB from the previous posts you received, possibly other
things, like what Martin pointed out where you were using a string literal.
Also, as Bob pointed out, you only need 'change' rights, not full rights for
the IUSR account for the folder where the db resides.

rs("somevariable") will also work but it is not the suggested format to use.

Bob pointed the most important thing here. It is ALWAYS a good idea to
write your responses to the screen to verify what you're getting is what
you're expecting. This could have shown you:

provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:accessnewres.mdb

....which is probably what you were getting... Most of us use VBScript for
ASP coding so "provider=Microsoft.Jet.OLEDB.4.0; Data
Source=d:\access\newres.mdb" is appropriate and easily overlooked when
someone is using J(ava)Script.

Glida Radner, as Rosanna Rosanna Danna, said it best, "That just goes to
show ya'. It's always something." (O:=

Glad you got it working.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top