Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 August 23rd, 2007, 08:14 AM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP / ADODB - How to close connection?

Hi - appreciate any help and pointers.

Say, I have the following files

oracle.asp
----------
Function GetDBConnection()

  Dim cConnection

  cConnection = "Provider=MSDAORA;Data Source=xxx.world;User Id=xxx;Password=xxxx;"

  Dim objConnection

  Set objConnection = Server.CreateObject("ADODB.Connection")
  objConnection.ConnectionString = cConnection
  objConnection.CursorLocation = 3
  objConnection.Open

  Set GetDBConnection = objConnection

End Function
%>

getRecord.asp
-------------

  ' RECORDSET
  Set rs=Server.CreateObject("ADODB.Recordset")

  ' GET SOMETHING
  strSql = "SELECT XXX"

  rs.Open strSql, GetDBConnection()

  ' DO SOMETHING WITH RS

  rs.Close
  Set rs = nothing

  ' HOW DO I CLOSE THE CONNECTION??

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''
I tried doing this:

Dimm conn
conn = GetDBConnection()

conn.Close

but it errors out with

******************************************
Object required: 'Provider=MSDAORA.1;P'
******************************************

Thanks.
 
Old August 23rd, 2007, 08:16 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Have you tried:

Dim conn
Set conn = GetDBConnection()

conn.Close

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 23rd, 2007, 08:34 AM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I did. In my OP, you can see it:

'''''''''''''''''''''''''''''''''''''''''''''''''' ''''
I tried doing this:

Dimm conn
conn = GetDBConnection()

conn.Close

but it errors out with

******************************************
Object required: 'Provider=MSDAORA.1;P'
******************************************


I did the following now:

***************************
  ' RECORDSET
  Set rs=Server.CreateObject("ADODB.Recordset")

  rs.ActiveConnection = GetDBConnection()

  ' GET SOMETHING
  strSql = "SELECT XXX"

  rs.Open strSql

  ' DO SOMETHING WITH RS

  rs.Close
  Set rs = nothing

*********************************

Now when I read about ADO connection (link below) does it mean it is implementing some sort of connection pooling?? It will be hard for me to get answers from the server folks nor can I monitor any connection to the Oracle server. Just want to make sure I don't tied up any unnecessary resources or wait for IIS/Oracle to timeout any open connection.

http://www.w3schools.com/ado/prop_comm_activeconn.asp

The ActiveConnection property tells which Connection object the Command object belongs to.

If the connection is closed, it sets or returns a definition for a connection. If the connection is open it sets or returns the current Connection object.

EDIT -- I did this now: rs.ActiveConnection.Close

Can someone clarify how the bold item above works? Can someone provide sample code on how to implement it?

Most examples I've found usually have all the connection, sql, rs, close all in 1 ASP script.
 
Old August 23rd, 2007, 10:36 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

No, it's different:

Dim conn
Set conn = GetDBConnection()

versus

Dimm conn
conn = GetDBConnection()

I added a Set statement.....

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
 
Old August 24th, 2007, 01:43 PM
Registered User
 
Join Date: Aug 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar.. thanks for pointing that out. I'm new at writing ASP.

This is what I'm doing now. Is it the proper method? Any suggestions? Thanks.

oracle.asp
----------
Function GetDBConnection()
  Dim cConnection

  cConnection = "Provider=MSDAORA;Data Source=xxx.world;User Id=xxx;Password=xxxx;"

  Dim objConnection

  Set objConnection = Server.CreateObject("ADODB.Connection")
  objConnection.ConnectionString = cConnection
  objConnection.CursorLocation = 3
  objConnection.Open

  Set GetDBConnection = objConnection

End Function
%>

getRecords.asp
--------------

  Set objCmd = Server.CreateObject("ADODB.Command")
  objCmd.ActiveConnection = GetDBConnection()
  objCmd.CommandType = 1

  ' GET SOMETHING
  strSql = "SELECT xxx"
  objCmd.CommandText = strSql
  Set rs = objCmd.Execute()

  ' DO SOMETHING WITH rs

  rs.Close
  objCmd.ActiveConnection.Close
  Set rs = Nothing






Similar Threads
Thread Thread Starter Forum Replies Last Post
Help.Can i use ADODB.Connection with DetailsView? aekta ASP.NET 2.0 Professional 5 March 11th, 2007 06:08 AM
ADODB.Connection on every page? Steve777 Classic ASP Professional 10 September 13th, 2006 08:19 AM
ADODB.Connection (0x800A0E7A) sumanst Classic ASP Databases 1 August 5th, 2005 02:56 PM
ADODB connection for Recordset dpatole Beginning VB 6 1 October 14th, 2003 04:24 PM
ADODB Connection String misterqj Access 2 September 30th, 2003 06:30 AM





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