Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Read an Access database using Server-side


Message #1 by "Sunil Bharuchi" <sunilbharuchi@b...> on Mon, 26 Feb 2001 17:50:13
I'm trying to read an Access database using JScript, I'm getting an

'object expected' error when I run my ASP file.  I've tried reading an

Access database using VBScript and it works.  Please help.



Both code listings follow:



<%@ Language = JScript %>

<%//@Language = VBScript%>

<%//Option Explicit%>

<%//All page references are from "Active Server Pages 3.0 Visual"%>

<%Response.Buffer = true // or = false - pg. 89%>

<%Response.Expires = -1500 //Don't place in cache - pg. 112%>

<%Response.ContentType = "text/html" // pg. 114%>

<%//Response.AddHeader = "Content-Language", "en" JavaScript   //doesn't



support this feature  pg. 116%>

<!--#include virtual="/includes/adovbs_JScriptVersion.inc"-->

<%

    //Open up a connection to our Access database

    var objConn = null;

    //objConn = new ActiveXObject("ADODB.Connection");

    objConn =  Server.CreateObject("ADODB.Connection");

    objConn.ConnectionTimeout=60;



    //Using DSN Connection

    objConn.Open("DSN=pg499DB");



    //Create a recordset object instance and retrieve the information

    //from the Friends table.

    var objRS = null;

    //objRS = new ActiveXObject("ADODB.Recordset");

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

    objRS.Open("SELECT * FROM Friends", objConn);

    //vbScript --- objRS.Open "Friends", objConn, , , adCmdTable



    //Display the contents of the Friends table





    objRS.MoveFirst();

    //Object Expected - Error message here.

    While(! objRS.EOF)

    {

       Response.Write("<B>" + objRS("Name") + "</B><BR>");

       Response.Write(objRS("StreetAddress") + "<BR>");

       Response.Write(objRS("City") + ", " + objRS("State"));

       Response.Write("<BR>" + objRS("Zip") + "<BR>");

       Response.Write(objRS("PhoneNumber") + "<P><HR><P>");



       //Move to the next row in the Friends table

       objRS.MoveNext();

     //Loop

    }



    //Clean up our ADO objects

    objRS.Close();

    objRS = null;



    objConn.Close();

    objConn = null;

%>









<%@ Language = VBScript %>

<% Option Explicit %>

<!--#include virtual="includes/adovbs_VBScriptVersion.inc"-->

<%

    'Open up a connection to our Access database

    'We will use a DSN-less connection.

    Dim objConn

    Set objConn = Server.CreateObject("ADODB.Connection")

    objConn.ConnectionTimeout=60

    '

    '///////////////////////////////

    'objConn.ConnectionString = "DRIVER={Microsoft Access Driver

(*.mdb)};" & _

    '                           "DBQ=C:\My

Documents\FriendsContactInfo.mdb"

    'objConn.ConnectionString = "DRIVER={Microsoft Access Driver

(*.mdb)};" & _

    '

"DBQ=C:\Scratch\Access2k\FriendsContactInfo.mdb"

    '///////////////////////////////

    '

    'Using DSN Connection

    objConn.Open "DSN=pg499DB"



    'Create a recordset object instance and retrieve the information

    'from the Friends table.

    Dim objRS

    Set objRS = Server.CreateObject("ADODB.Recordset")

    objRS.Open "SELECT * FROM Friends", objConn

    'objRS.Open "Friends", objConn, , , adCmdTable



    'Display the contents of the Friends table

    Do While Not objRS.EOF

       Response.Write "<B>" & objRS("Name") & "</B><BR>"

       Response.Write objRS("StreetAddress") & "<BR>"

       Response.Write objRS("City") & ", " & objRS("State")

       Response.Write "<BR>" & objRS("Zip") & "<BR>"

       Response.Write objRS("PhoneNumber") & "<P><HR><P>"



       'Move to the next row in the Friends table

       objRS.MoveNext

    Loop





    'Clean up our ADO objects

    objRS.Close

    Set objRS = Nothing



    objConn.Close

    Set objConn = Nothing

%>



Message #2 by "Blake, Shane" <Shane.Blake@p...> on Mon, 26 Feb 2001 13:49:25 -0500
jscript is case sensitive...



use 'while (!objRS.EOF)' not 'While(! objRS.EOF)'  



that may be it...  if not, let me know and i'll send some examples of using

jscript (since that's my primary asp language these days, i've found a few

idiosyncrasies)



shane


  Return to Index