Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript
|
BOOK: Beginning JavaScript
This is the forum to discuss the Wrox book Beginning JavaScript by Paul Wilton; ISBN: 9780764544057
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning JavaScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 18th, 2004, 03:00 PM
Registered User
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default JavaScript connection string for Access database

I'm working in chapter 10 of Beginning JavaScript. I'm trying to make a DSN-less connection to an Access database. I've searched the p2p forums and archives, but haven't seen any discussion of this topic. I've spent much time searching other sites for some discussion of this issue.

I'm working on a Win 98 machine with PWS installed. For testing, the database has just one table "names" which has tow fields "Firstname" and "Lastname." I can make this connection with a DSN and I can make a DSN-less connection in VBScript; however, I would like to be able to make an DSN-less connection in JavaScript because I will not have access to the server on which I will be deploying my finished products.

Following is some of the code with an explanation of some of the problems I have been having:

<%@ Language = JavaScript %>

<%
var appPath = Server.MapPath("JavaBase.mdb");

var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + appPath + ";Persist Security Info=False";

var strSQL = "SELECT * FROM Names";

var strConnection = Server.CreateObject("ADODB.Connection");
strConnection.Open(strConn);

var objRS;
/*The next line of code gives the following error:
error '80004005'
Unspecified error
*/
//objRS = strConnection.Execute(strSQL)

var objRS = Server.CreateObject("ADODB.Recordset");

/*This line of code works fine with the DSN connection*/
//objRS.Open(strSQL, "DSN=JavaTest", 3);


/*However, this line of DSN-less connection gives the following error:
error '80004005'
Unspecified error
*/
//objRS.Open(strSQL, strConn, 3);


%>

Any suggestion will be greatly appreciated.
clblack



Claude
 
Old January 19th, 2004, 01:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear friend:
Im not good at Access & traditional ASP & only i have this code to retrive my info from Access via ASP 3.0, I hope this sample will help u, but its in VB Script.
Code:
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>List</title>
</head>

<%
Response.Expires = 0

   MYSQL="SELECT * FROM Names"

   database = "JavaBase.mdb"
   connectString ="Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source= " & Server.MapPath(database)
   set conn=CreateObject ("Adodb.connection")
   conn.Open connectString

    Set rs=Server.CreateObject("ADODB.Recordset")
    rs.CursorLocation =3  
    rs.LockType =2

    set rs.ActiveConnection=conn
    rs.Open MYSQL
%>
<body>       
 <table border=1 align="center">
   <tr>
     <td><b>Time</b></td>
     <td><a href="javascript:location.reload();"><img alt="refresh page"></a></td>
 <%   
   do while not rs.EOF
     Response.Write("<tr><td>" & rs("Feild_1") & "</td>")
     Response.Write("<td>" & rs("Feild_2") & "</td></tr>")

     rs.MoveNext()
   loop

    rs.Close()
    conn.Close()
    set rs = nothing
    set conn = nothing

 %>
 </table>

</body>

</html>
Always:),
Hovik Melkomian.
 
Old January 19th, 2004, 07:50 PM
Registered User
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Hovik Melkomian. I'll give this a try. However, JavaScript does things a bit differently than VBScript. I can get the connection and recordset to work in VBScript, but I'm trying to develop JavaScript skill. I am aware that VBScript is closely married to ASP, but I think JavaScript should also work with ASP. As I mentioned above, I can get the connection to work with a DSN, but I want a DSN-less connection because I don't have ready access to the server to set up a DSN. And DSNs suffer a performance loss because the script has to keep running throug the registry to check the connection string rather than a direct connection with a DSN-less connection string.

Again, thanks for your help.

clblack

Claude
 
Old January 21st, 2004, 02:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Actually DNS is not good for web connections since u wont have much more facilities on WEB SERVER as u have on LOCALHOST (I think so). Yes u r right JavaScript can work with ASP too, but as I said I have not much experiance in SERVER CODING with JavaScript! I prefer to work with JavaScript, but in clint cide! In the other hand, Microsoft has back to JavaScript & u'll need to work with VBScript anymore...

The sample I gave u, is a DNS less connection & right now its working on server, so if u change it to JavaScript it should work too!


Always:),
Hovik Melkomian.
 
Old January 21st, 2004, 06:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I have successfully used this js code client-side to connect to an access db on a LAN:
Code:
  var adOpenForwardOnly = 0, adLockReadOnly = 1;
  var conn = new ActiveXObject("ADODB.Connection");
  conn.open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\\\server\\share\\db.mdb;Persist Security Info=False");
  if (conn)
  {
    var rs = new ActiveXObject("ADODB.Recordset");
    rs.Open("SELECT TOP 1 * FROM GPX ORDER BY EffectiveDate DESC", conn, adOpenForwardOnly, adLockReadOnly);
    if (rs && !rs.EOF)
    {
      var dtEff = new Date(rs.Fields("EffectiveDate").Value);
      ...
I'm guessing here, but maybe MapPath doesn't give the path in a suitable format for JS (since \ is a special char in JS, you have to double it up in paths). Just to see, try hard-coding the path and see if it connects then.

hth
Phil
 
Old January 21st, 2004, 08:42 AM
Registered User
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help. I'll give this a try and let you know.
Cblack

Claude
 
Old March 15th, 2004, 12:11 AM
Registered User
 
Join Date: Mar 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to zenitha Send a message via Yahoo to zenitha
Default

i already use that code (using ActiveXObject) but i get this message:
"This page is accessing a data source on another domain. Do you want to allow this?"
if my answer is Yes then the script has been run well but if my answer is No then there is nothing to run.
What should i do to hide or erase that message? why that message appear? help me please...

thanks before
 
Old January 28th, 2006, 05:56 AM
Registered User
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default


if u got this solution problem, pls. send me what's it's solution.
my mail id is [email protected]



Quote:
quote:Originally posted by zenitha
 i already use that code (using ActiveXObject) but i get this message:
"This page is accessing a data source on another domain. Do you want to allow this?"
if my answer is Yes then the script has been run well but if my answer is No then there is nothing to run.
What should i do to hide or erase that message? why that message appear? help me please...

thanks before
naresh
 
Old April 24th, 2006, 04:32 PM
Registered User
 
Join Date: Apr 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to credondo Send a message via Yahoo to credondo
Default

I have the same prompt security message behavior using AJAX within an IFRAME. Any ideas of how to avoid this message prompt?



 
Old July 24th, 2007, 06:34 AM
Registered User
 
Join Date: Jul 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes,
if you add the website as "trusted" in your web browser it should stop asking for confirmation.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection String to MS ACCESS jmss66 Classic ASP Databases 4 January 24th, 2008 06:54 PM
Database Connection using VBScript (or) JavaScript reachsevar ASP.NET 1.0 and 1.1 Basics 1 November 27th, 2007 10:54 AM
Database connection with javascript rupen Javascript 5 April 20th, 2006 09:10 AM
Connection string to Oracle Database phudong3da Dreamweaver (all versions) 2 May 2nd, 2005 07:13 PM
Pocket Access Database Connection String mythios VS.NET 2002/2003 0 August 28th, 2003 12:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.