Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Beginning JavaScript
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 18th, 2004, 02:00 PM
Registered User
 
Join Date: Jan 2004
Location: Franklin Springs, GA, USA.
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
__________________
Claude
Reply With Quote
  #2 (permalink)  
Old January 19th, 2004, 12:51 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Canada
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik Send a message via Skype™ 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.
Reply With Quote
  #3 (permalink)  
Old January 19th, 2004, 06:50 PM
Registered User
 
Join Date: Jan 2004
Location: Franklin Springs, GA, USA.
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
Reply With Quote
  #4 (permalink)  
Old January 21st, 2004, 01:40 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Canada
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik Send a message via Skype™ 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.
Reply With Quote
  #5 (permalink)  
Old January 21st, 2004, 05:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
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
Reply With Quote
  #6 (permalink)  
Old January 21st, 2004, 07:42 AM
Registered User
 
Join Date: Jan 2004
Location: Franklin Springs, GA, USA.
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
Reply With Quote
  #7 (permalink)  
Old March 14th, 2004, 11:11 PM
Registered User
 
Join Date: Mar 2004
Location: Pasar Minggu, DKI Jakarta, Indonesia.
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
Reply With Quote
  #8 (permalink)  
Old January 28th, 2006, 04:56 AM
Registered User
 
Join Date: Jan 2006
Location: ahmedabad, gujarat, India.
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 nareshprajapati_9@yahoo.com



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
Reply With Quote
  #9 (permalink)  
Old April 24th, 2006, 04:32 PM
Registered User
 
Join Date: Apr 2006
Location: Miami, Florida, USA.
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?



Reply With Quote
  #10 (permalink)  
Old July 24th, 2007, 06:34 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
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.



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection String to MS ACCESS jmss66 Classic ASP Databases 4 January 24th, 2008 05:54 PM
Database Connection using VBScript (or) JavaScript reachsevar ASP.NET 1.0 and 1.1 Basics 1 November 27th, 2007 09: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



All times are GMT -4. The time now is 03:47 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.