Re: Access Query w/VBScript
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Sun, 12 Jun 2005 07:31:08 -0400
Bob wrote:
> I am a VBA programmer learning ASP.
>
> The code below is my attempt to access a database
> (C:\Bob\Personnel.mdb) and run a query that's stored there (qrySel")
> using an IIS server. I am using 'Beginning ASP Databases' and
> starting with chapter 8, this method is used to run queries.
>
> <SCRIPT LANGUAGE="VBScript">
> <HEAD>
> <TITLE>Use Access Query as Source</TITLE>
> </HEAD>
> <BODY>
>
> <%
> Dim objRS, adOpenForwardOnly
> adOpenForwardOnly = 0
>
> Set objRS = Server.CreateObject("ADODB.Recordset")
> objRS.Open "qrySel", "DSN=PersonnelTest", adOpenForwardOnly
Always use an explicit Connection object. Using a connection string in your
recordset's Open statement disables connection pooling - this can kill
performance. Also, avoid using the obsolete ODBC provider. Use the native
Jet OLE DB provider instead. Here is how I would call your query (I assume
it is a saved query - I am also assuming the query returns only the lastName
field - you wouldn't be wastefully retrieving unneeded data across the wire
would you?):
Set cn = createobject("adodb.connection")
cn.open "Provider="microsoft.jet.olecb.4.0;" & _
"Data Source=c:=path\to\database.mdb"
Set objRS = CreateObject("ADODB.Recordset")
cn.qrySel objRS
if not objRS.EOF then Response.Write objRS(,,"","<P>")
objRS.Close
Set objRS=nothing 'don't forget the Set keyword ...
Here is some more information about calling saved queries:
http://www.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=e6lLVvOcDHA.1204%40TK2MSFTNGP12.phx.gbl
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&c2coff=1&selm=eHYxOyvaDHA.4020%40tk2msftngp13.phx.gbl
http://groups-beta.google.com/group/microsoft.public.inetserver.asp.db/msg/b3d322b882a604bd
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"
.
- Follow-Ups:
- Re: Access Query w/VBScript
- From: Bob Orta
- Re: Access Query w/VBScript
- References:
- Access Query w/VBScript
- From: Bob
- Access Query w/VBScript
- Prev by Date: Re: time and or day of week
- Next by Date: Re: Retireving numbers from a string in RegExp
- Previous by thread: Re: Access Query w/VBScript
- Next by thread: Re: Access Query w/VBScript
- Index(es):
Relevant Pages
|