473,378 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Caching a sqlconnection

I am developing a asp.net 2.0 app using vb and am thinking about using the
system cache to cache a sqlconnection. However, I am concerned there might be
implications to this which are not obvious.

Can anybody offer any thoughts on whetehr this might be a good or bad idea?

Thanks

Robert
Nov 16 '07 #1
7 2100
Don't bother. Just ensure you close and dispose your connections after
every use, and let the connection-pool do its job. Closing a
SqlConnection doesn't close the *actual* connection - it just releases
it to the pool for re-use.

Marc
Nov 16 '07 #2
The reason I am interested in doing it is that it saves code. To open a
connection, I have to go to the trouble of setting the connection string,
catching and handling exceptions....

To get it from the cache, I just

dim conn as sqlconnection = new sqlconnection
if not isnothing(cache("conn")) then
conn=cache("conn")
else
set up conn, open conn, handle errors, cache conn...
end if

"Marc Gravell" wrote:
Don't bother. Just ensure you close and dispose your connections after
every use, and let the connection-pool do its job. Closing a
SqlConnection doesn't close the *actual* connection - it just releases
it to the pool for re-use.

Marc
Nov 16 '07 #3
in asp.net? that means that every request is going to be trying to use
*the same* connection. Not even "MARS" is that good...
Seriously, people have spent a lot of time getting pooling "right"...
and it isn't any more code:

using(SqlConnection conn = new SqlConnection(someString)) {
conn.Open();
}

that's it! I'm sure VB.NET has a "using" equivalent... (I'm a C# guy
so can't say 100%)

Marc
Nov 16 '07 #4
I have a "utility" connection in the code that is used for performing
"plumbing" type tasks - building controls, logging error messages, reading
system parameters from a parameter table, logging in a user, etc... That is
the connection I would be caching.

However, your comment tells me that I might be overloading the connection
when there are many sessions so that is the sort of thing I was wondering
about.

Thanks.

"Marc Gravell" wrote:
in asp.net? that means that every request is going to be trying to use
*the same* connection. Not even "MARS" is that good...
Seriously, people have spent a lot of time getting pooling "right"...
and it isn't any more code:

using(SqlConnection conn = new SqlConnection(someString)) {
conn.Open();
}

that's it! I'm sure VB.NET has a "using" equivalent... (I'm a C# guy
so can't say 100%)

Marc
Nov 16 '07 #5
I thought I read that connection pooling is automatic - ( not using mars ), that if
all the parameters are the same as what the last connection pool was, it uses the
connection from the pool.

Change anything - even as far as a variable name, its considered a new connection.

So the trick is to always use the same "my.connection" setting or whatever ur variable is.

I may have read it wrong / and be completely wrong - im a newbie.

M.

Rbrt wrote:
I have a "utility" connection in the code that is used for performing
"plumbing" type tasks - building controls, logging error messages, reading
system parameters from a parameter table, logging in a user, etc... That is
the connection I would be caching.

However, your comment tells me that I might be overloading the connection
when there are many sessions so that is the sort of thing I was wondering
about.

Thanks.

"Marc Gravell" wrote:
>in asp.net? that means that every request is going to be trying to use
*the same* connection. Not even "MARS" is that good...
Seriously, people have spent a lot of time getting pooling "right"...
and it isn't any more code:

using(SqlConnection conn = new SqlConnection(someString)) {
conn.Open();
}

that's it! I'm sure VB.NET has a "using" equivalent... (I'm a C# guy
so can't say 100%)

Marc
Nov 16 '07 #6
RbrtI have a "utility" connection in the code that is used for
performing "plumbing" type tasks
cache the connection string; let the connection-pool worry about the
rest. Honestly, this is the best approach. Otherwise you will have
concurrency and/or scalability issues.

MiroI thought I read that connection pooling is automatic <snip>
Your understanding is correct; it simply compares the connection
string. Note that pooling can be disabled, and isn't enabled by
default on all providers - but with SqlClient it is.

Marc
Nov 16 '07 #7
(and when I say "cache", I mean for instance in a static field, not
the asp.net cache)
Nov 16 '07 #8

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

Similar topics

0
by: Troy Simpson | last post by:
Hi, I have a website which is made up of dynamic pages. Each page that's loaded has some code which looks at which template to load amongst other things, which causes the page to take a little...
5
by: DC Gringo | last post by:
I am having a problem reading a simple update to the database. Basically I'm testing a small change to the pubs database -- changing the price of the Busy Executive's Database Guide from 19.99 to...
5
by: Raj | last post by:
What is the purpose of file system caching while creating a tablespace? Memory on the test server gets used up pretty quickly after a user executes a complex query(database is already activated),...
5
by: Antonio | last post by:
Hi, everyone. Can someone direct me to the "how-to" on cachine data from a sql to a datagrid? Thanks
2
by: George1776 | last post by:
All, I've recently upgraded our production ASP.NET/C# application from framework 1.1 to 2.0. Since then I've been plagued by out-of-memory errors and problems with the cache object (which may...
4
by: Hermann | last post by:
My site is a bit slow showing the main page so I thought caching query result in PHP will improve performace. Then I read MySQL documentation and saw that MySQL does have a caching feature. So......
2
by: Toni | last post by:
Hello! I'm trying to use ASP.NET caching with my web site and SQL Server, but I have a problem. I try to do everything according to the instructions like this page here:...
0
by: Toni | last post by:
Hello! I'm trying to get caching work with ASP.NET 2.0 and SQL Server Express Edition 2005, but I have a problem and I can't figure out what I'm still doing wrong. I have enabled the database...
1
by: Andrus | last post by:
In Winform RDLC reports running in local mode I use expressions like =Customer.GetName(Fields!CustiId.Value) GetName() family of functions are implemented in static assembly (CodeModule) as ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.