473,804 Members | 3,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADO connection pooling and pepared statements

I have an ASP (IIS 4.0) based website fronting a SQL Server 2000
database. I am trying to avoid using dynamic SQL for queries, and I am
considering prepared statements as an alternative...

All the advice I have seen strongly suggests that connection objects
should not be explicitly cached, either at the application or session
level. Therefore, I am creating a connection for each page (same
connection string), and closing it immediately after use. By my
understanding, this is utilising the MTS connection pool and is the
most resource efficient method to use.

However, I have seen a number of comments to the effect that connection
pooling and prepared statements do not mix.

For example...

"Avoid creating prepared statements or temporary stored procedures.
These create server resources attached to a specific connection.
Because you might not get the same connection from the pool the next
time you ask for one, you lose the benefit of creating them in the
first place. Worse, because the connection might reside in the pool for
a long time, it can get clogged up with the useless but expensive
server resources created by each "user" that creates them." - Rob
Macdonald
(http://msdn.microsoft.com/library/de...0/html/Rob.asp)

Is this still the case? This article was written in 2000, and I was
hoping there was now some workaround for this. Are there any SQL
Server/driver level settings that can fix or alleviate this problem.
Are there any other options besides prepared statements or stored
procedures? Thanks.

Jul 23 '05 #1
2 2077
mo*******@hotma il.com wrote:
I have an ASP (IIS 4.0) based website fronting a SQL Server 2000
database. I am trying to avoid using dynamic SQL for queries, and I am considering prepared statements as an alternative...

All the advice I have seen strongly suggests that connection objects
should not be explicitly cached, either at the application or session
level. Therefore, I am creating a connection for each page (same
connection string), and closing it immediately after use. By my
understanding, this is utilising the MTS connection pool and is the
most resource efficient method to use.
Yes.
That's the way everyone I know does it.

However, I have seen a number of comments to the effect that connection pooling and prepared statements do not mix.


I don't think I've ever seen prepared statements used in an app.

I reckon you should instead be considering stored procedures.
Won't you still be running the risk of code injection if you go for
prepared statements?

Jul 23 '05 #2
(mo*******@hotm ail.com) writes:
I have an ASP (IIS 4.0) based website fronting a SQL Server 2000
database. I am trying to avoid using dynamic SQL for queries, and I am
considering prepared statements as an alternative...

All the advice I have seen strongly suggests that connection objects
should not be explicitly cached, either at the application or session
level. Therefore, I am creating a connection for each page (same
connection string), and closing it immediately after use. By my
understanding, this is utilising the MTS connection pool and is the
most resource efficient method to use.

However, I have seen a number of comments to the effect that connection
pooling and prepared statements do not mix.


I think there is some confusion here. What you really want is parameterized
queries:

SELECT col1, col2 FROM tbl WHERE thiscol = ? AND thatcol = ?

You can sett the .Prepared property to true, but that is not really the
main thing with leaving completely dynamically built SQL statements
behind. The above query will get cached in the procedure cache of
SQL Server, so any connection can reuse it.

--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
3253
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection which must be closed first." As suggested, I was closing the connection in the Finally part of the outer Try but I wasn't closing the data reader as well so I assume that if the following happens, the above error could occur
1
5731
by: Lenny Shprekher | last post by:
Hi, I am getting issues that Oracle collecting opened sessions (connections) from my webservice using regular System.Data.OleDb.OleDbConnection object. I am guessing that this is connection pooling issue. Is there is any way to disable connection pooling for one particular .net webservice? Thanks, Leonid
7
2210
by: Mrinal Kamboj | last post by:
Hi , I am using OracleConnection object from Oracle ODP.net provider and following is the behaviour which i am finding bit strange : To start with my argument is based on followings facts : 1. Connection object is a reference type object . 2. All reference types are passed by reference even when done without using modifier like ref / out .
3
10299
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not available...)? Are there any strategies to detect this broken connections, and how can I
29
7079
by: Bryce K. Nielsen | last post by:
Suddenly this week, I've started getting this error message: System.Data.SqlClient.SqlConnection(GetOpenConnection)ExecuteNonQuery requires an open and available Connection. The connection's current state is connecting. I'm very puzzled since I'm not calling "ExecuteNonQuery" and I am calling "Open", which I've always assumed was Synchronous, i.e. would not return until either A) the connection was open or B) there was an error. Here...
2
2350
by: JimLad | last post by:
Hi, In an existing ASP/ASP.NET 1.1 app running on IIS 6, I need to RELIABLY pass the logged in username through to the SQL Server 2000 database for auditing purposes. The current method is hideously unreliable. The app includes updategrams, XML Templates and ADO connections. I don't want to use impersonation because of the direct db access that allows.
16
2877
by: crbd98 | last post by:
Hello All, Some time ago, I implemented a data access layer that included a simple connectin pool. At the time, I did it all by myself: I created N connections, each connection associated with a worker thread that would execute the db commands. The pool was fixed and all the connections were created when the db access class was instantiated. The connections remained opened during the whole execution. If a connection was not available...
3
4895
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable g_sConnectionString and leave this connection open and not close it until it exits the application. Then on each thread/each subsequent sub that needs the connection I create a local OleDBConnection variable, open the connection using the exact...
0
6626
viswarajan
by: viswarajan | last post by:
Introduction This article is to go in deep in dome key features in the ADO.NET 2 which was shipped with VS 2005. In this article I will go trough one of the key features which is the Connection Pooling. This feature is a key feature plays an important role in the performance in most of business application or Data driven application. What's Connection Pooling?
0
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10577
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10320
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9150
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5521
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.