Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 Q: Resource status on failure exit.
 New Topic  Topic Locked
 Printer Friendly
Previous Page | Next Page
Author Previous Topic Topic Next Topic
Page: of 3

Doug G
Support Moderator

USA
6493 Posts

Posted - 09 February 2003 :  20:56:00  Show Profile
quote:
Mmm, not a particularly good analogy Doug ...

Not me

Nikkol, my code usually looks like your 2nd example above.

======
Doug G
======
Computer history and help at www.dougscode.com
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 09 February 2003 :  21:20:07  Show Profile  Send ruirib a Yahoo! Message
I'm also under the impression that Nikkol's 2nd example is the most effective way do to it.


Snitz 3.4 Readme | Like the support? Support Snitz too

Edited by - ruirib on 09 February 2003 21:20:35
Go to Top of Page

Doug G
Support Moderator

USA
6493 Posts

Posted - 09 February 2003 :  22:24:40  Show Profile
quote:
Originally posted by Nikkol

I get the idea. Just was wondering the efficiency of opening db connection ... opening and closing multiple recordsets ... closing db connection VERSUS open db conn, open recordset, close recordset, close db conn multiple times. I use GetRows almost exclusively when I get recordsets, but usually i only open one connection to db.


If you don't have connection pooling working on your web server, opening a connection and keeping it open through your page is probably the more efficient route.

But, if you do use connection pooling leaving the connection open longer actually detracts from the effectiveness of pooling.

When the first user opens a db connection and then closes it, IIS connection pooling keeps the db connection open for a period of time after your page closed the connection. During that period of time, if another asp page on the same server needs a connection to the same database and opens a connection, the connection pooling system actually returns the already-open connection in response to the set MyConn = Server.CreateObject("ADODB.Connection") instead of going through the overhead of creating a new connection.

If, however, the connection is in use then a new connection object must be created by the server. If your page keeps the connection open for it's entire execution time, that page connection is unavailable to the pool of connections and other user's pages will need to create a new connection instead of sharing with you.

There are probably a lot of internal complexities to connection pooling, in fact there are some long papers on the subject on the MS website. Connection pooling was problematic with earlier versions of IIS and MDAC and had to be explicitly enabled. I believe connection pooling is turned on by default with IIS5.

======
Doug G
======
Computer history and help at www.dougscode.com

Edited by - Doug G on 09 February 2003 22:27:36
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 09 February 2003 :  22:26:39  Show Profile
quote:
Originally posted by HuwR


It is more like a room with many doors , but while you hold a door open nobody else can pass through it, closing it quickly allows someone else to use the door rather than have to wait or open find another door



I think that is what is important so that someone else can use it. Since all the doors lead to the same room does not matter which door you use. if every one holds the door open so that "nobody else can pass through it" than at somepoint the queue will start building...and there will be delay in getting into the room.

Edited by - GauravBhabu on 09 February 2003 22:36:53
Go to Top of Page

davemaxwell
Access 2000 Support Moderator

USA
3020 Posts

Posted - 09 February 2003 :  22:59:21  Show Profile  Visit davemaxwell's Homepage  Send davemaxwell an AOL message  Send davemaxwell an ICQ Message  Send davemaxwell a Yahoo! Message
According to a source I am working on a work-related project for, there is no real reason to open a connection at all. All you need to do is pass the Connection String to the recordset object and let it handle it on it's own. According to the guy I'm working with, this approach came directly from the ADO docs and is supposed to be much more efficient. I haven't taken the time to test it thoroughly to verify this claim, however.

Dave Maxwell
Barbershop Harmony Freak
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 09 February 2003 :  23:31:30  Show Profile
if you don't own the server, how can you tell if connection pooling is turned on (besides asking the host)?

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

HuwR
Forum Admin

United Kingdom
20600 Posts

Posted - 10 February 2003 :  03:07:59  Show Profile  Visit HuwR's Homepage
quote:
Originally posted by davemaxwell

According to a source I am working on a work-related project for, there is no real reason to open a connection at all. All you need to do is pass the Connection String to the recordset object and let it handle it on it's own. According to the guy I'm working with, this approach came directly from the ADO docs and is supposed to be much more efficient. I haven't taken the time to test it thoroughly to verify this claim, however.



yes, this is the way I use ADO when using it with delphi. each query has its own connection string there is no other db connection, each query opens its own as it needs it and closes it when its returned the results.
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 20 February 2003 :  03:14:50  Show Profile
any guru out there have time to give me an example on how to code the best way?
thanks.

Edited by - bjlt on 20 February 2003 03:15:16
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 20 February 2003 :  03:25:13  Show Profile
I'm not a Guru, but here is a code portion from my library I use in my last project (not throughly tested yet):

Function fAPG_DBGetRows(strSQL, intPageSize, intPage)
DIM my_Conn, rs, arr
	if not isNumeric(intPageSize) or not (intPageSize > 0) then intPageSize = 0
	if not isNumeric(intPage) or not (intPage > 0) then intPage = 0
	set my_Conn = Server.CreateObject("ADODB.Connection")
	my_Conn.Open strAPG_Connection
	set rs = Server.CreateObject("ADODB.Recordset")
	if intPageSize > 0 then rs.cachesize = intPageSize
	rs.open strSql, my_Conn, 3
	If not (rs.EOF or rs.BOF) then
		if intPageSize > 0 then rs.PageSize = intPageSize
		intAPG_DBQAllRecCount = cLng(rs.RecordCount)
		if intPage > 0 then rs.AbsolutePage = intPage
		intAPG_DBQPageCount = cLng(rs.PageCount)
		if intPage > 0 then
			arr = rs.GetRows(intPageSize)
		else
			arr = rs.GetRows()
		end if
		intAPG_DBQRecCount = UBound(arr, 2)
	else
		arr = Null
		intAPG_DBQRecCount = 0
		intAPG_DBQPageCount = 0
	end if
	rs.Close
	set rs = nothing
	my_Conn.Close
	set my_Conn = nothing
	fAPG_DBGetRows = arr
End Function


Except paging, you use it like:

' very global variables
dim intAPG_DBQAllRecCount, intAPG_DBQPageCount, intAPG_DBQRecCount

' some task specific array
Dim arr, i

strSql = "SELECT FIELD1, FIELD2 FROM MYTABLE"
arr = fAPG_DBGetRows(strSQL, 0, 0)
if intAPG_DBQRecCount > 0 then 'this is like rs.eof check
	for i=0 to intAPG_DBQRecCount-1
		'do some task
	next
else 'empty result
   'do alternative task
end if


I use a single connection string there, so I don't pass it as a parameter, but could be done...

Stop the WAR!

Edited by - Deleted on 20 February 2003 03:32:51
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 20 February 2003 :  05:26:26  Show Profile
Thanks bozden.

quote:
--------------------------------------------------------------------------------
Originally posted by davemaxwell

According to a source I am working on a work-related project for, there is no real reason to open a connection at all. All you need to do is pass the Connection String to the recordset object and let it handle it on it's own. According to the guy I'm working with, this approach came directly from the ADO docs and is supposed to be much more efficient. I haven't taken the time to test it thoroughly to verify this claim, however.

--------------------------------------------------------------------------------

how about this,
no real reason to open a connection at all. All you need to do is pass the Connection String to the recordset object and let it handle it on it's own.

Does it mean there's no need for con.open con.close and it's a better way to do the job?
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 20 February 2003 :  06:14:57  Show Profile
The more you try to optimize things, the less portable your code will be. If you start to use strict ADO methodology, you will need to add more checks/settings to prevent collapse.

For example, if you want to support MySql like Snitz does, the rs.cachesize will not work. So you set additional checks. Also a specific method/property could be added in vX.Y of ADO/MDAC/DCOM/Jet etc (whatever it is related with) and it will not work on other servers with older servers...

Here is the corrected function after some fixes:

Function fAPG_DBGetRows(strSQL, intPageSize, intPage)
DIM my_Conn, rs, arr
	if not isNumeric(intPageSize) or not (intPageSize > 0) then intPageSize = 0
	if not isNumeric(intPage) or not (intPage > 0) then intPage = 0
	set my_Conn = Server.CreateObject("ADODB.Connection")
	my_Conn.Open strAPG_Connection
	set rs = Server.CreateObject("ADODB.Recordset")
	if (intPageSize > 0) AND (strAPG_DataBaseType <> "mysql") then rs.cachesize = intPageSize
	rs.open strSql, my_Conn, adOpenStatic, adLockReadOnly, adCmdText
	If not (rs.EOF or rs.BOF) then
		if intPageSize > 0 then rs.PageSize = intPageSize
		intAPG_DBQAllRecCount = cLng(rs.RecordCount)
		if intPage > 0 then rs.AbsolutePage = intPage
		intAPG_DBQPageCount = cLng(rs.PageCount)
		if intPage > 0 then
			arr = rs.GetRows(intPageSize)
		else
			arr = rs.GetRows()
		end if
		intAPG_DBQRecCount = UBound(arr, 2)+1
	else
		arr = Null
		intAPG_DBQAllRecCount = 0
		intAPG_DBQRecCount = 0
		intAPG_DBQPageCount = 0
	end if
	rs.Close
	set rs = nothing
	my_Conn.Close
	set my_Conn = nothing
	fAPG_DBGetRows = arr
End Function


I didn't try the method davemaxwell suggested, so I cannot comment on it. Here is the ADO documentation I just read about recordset.ActiveConnection property in different places but no mention on performance...



Stop the WAR!
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 20 February 2003 :  06:47:05  Show Profile
bozden, if I use this function in snitz, will it fix the problem discussed before about time out error with large number of recordsets?
http://forum.snitz.com/forum/topic.asp?TOPIC_ID=39901
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 20 February 2003 :  07:03:10  Show Profile
How can I know without trying? As I said before, this is not Snitz code...

Stop the WAR!
Go to Top of Page

bjlt
Senior Member

1144 Posts

Posted - 20 March 2003 :  08:18:10  Show Profile
strange, I did a quicky test using

open db
open recordset1
close recordset1
close db
open db
open recordset2
close recordset2
close db

instead of opening db at the top/closing db at the end.

my default page (not snitz) takes 0.6sec to generate instead of 0.1sec before. it seems to be much slower.
I did it on win2k access2000, pIII 866 128M Ram, me as the only user.

Any idea?

Edited by - bjlt on 20 March 2003 13:28:47
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 20 March 2003 :  13:16:09  Show Profile
I don't understand ... Which one is what and which is slower?

Stop the WAR!
Go to Top of Page
Page: of 3 Previous Topic Topic Next Topic  
Previous Page | Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.39 seconds. Powered By: Snitz Forums 2000 Version 3.4.07