Hi and regards
What is best method to have an connection to sql, iam using sqlserver
1. have an sqlconnection open when the application start event in
global.asax so that i dont have to open it in each method where i
require to open an connection
2. open an connection in seesion so that, it is available in session of
the user thorugh out
3. open an connection in each method and close after the requried
operation is completed
which is better
as per the 3rd method ... doest openning and closing in each method is
a bad??
Comments expected 3 1929
1. This is the most horrible method. All users would share the same
connection object, which means, you are going to have multiple threads
trying to use it at once, which means your app will crash instance under any
kind of load.
2. This is slightly better, but still really bad. First off, it means you
have an open connection the entire lifetime of a session. This severely
limits the number of concurrent users, and performs badly.
3. This is how you should handle it. Connections are pooled by default,
opening and closing them is relatively inexpensive. Additionally, you will
get much better performance by not keeping unecessary connections open, 99%
of which time they are not being used.
So yes, #3 is the way to go.
"pratham" <pr************ @gmail.comwrote in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
Hi and regards
What is best method to have an connection to sql, iam using sqlserver
1. have an sqlconnection open when the application start event in
global.asax so that i dont have to open it in each method where i
require to open an connection
2. open an connection in seesion so that, it is available in session of
the user thorugh out
3. open an connection in each method and close after the requried
operation is completed
which is better
as per the 3rd method ... doest openning and closing in each method is
a bad??
Comments expected
Thanks Marina for that fast and detailed reply Cheers :)
Marina Levit [MVP] wrote:
1. This is the most horrible method. All users would share the same
connection object, which means, you are going to have multiple threads
trying to use it at once, which means your app will crash instance under any
kind of load.
2. This is slightly better, but still really bad. First off, it means you
have an open connection the entire lifetime of a session. This severely
limits the number of concurrent users, and performs badly.
3. This is how you should handle it. Connections are pooled by default,
opening and closing them is relatively inexpensive. Additionally, you will
get much better performance by not keeping unecessary connections open, 99%
of which time they are not being used.
So yes, #3 is the way to go.
"pratham" <pr************ @gmail.comwrote in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
Hi and regards
What is best method to have an connection to sql, iam using sqlserver
1. have an sqlconnection open when the application start event in
global.asax so that i dont have to open it in each method where i
require to open an connection
2. open an connection in seesion so that, it is available in session of
the user thorugh out
3. open an connection in each method and close after the requried
operation is completed
which is better
as per the 3rd method ... doest openning and closing in each method is
a bad??
Comments expected
Correct (on an earlier post) that #1 is really bad. #2 isn't good either.
An environment like the web, you especially want to
"Open Late" and "Close asap" model.
Open and close as fast as you can.
"pratham" <pr************ @gmail.comwrote in message
news:11******** *************@e 3g2000cwe.googl egroups.com...
Hi and regards
What is best method to have an connection to sql, iam using sqlserver
1. have an sqlconnection open when the application start event in
global.asax so that i dont have to open it in each method where i
require to open an connection
2. open an connection in seesion so that, it is available in session of
the user thorugh out
3. open an connection in each method and close after the requried
operation is completed
which is better
as per the 3rd method ... doest openning and closing in each method is
a bad??
Comments expected This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Donnie Darko |
last post by:
I'm trying to understand SqlConnection(), SqlCommand()
For example. I use SqlConnection() as a parameter when I create a new
SqlCommand. Then I open SqlConnection(), then I execute the SqlCommand().
At that point I cannot use SqlConnection() again. Unless I .Close() it and
then .Open it right?
Then what is 'connection pooling' ?
Can't I run multiple SqlCommand()s on the same SqlConnection() somehow ?
|
by: ed_p |
last post by:
Hello,
I have implemented the singleton pattern for a class to hold a
SqlConnection object that
will be used thruout the application to create commands. My application
is a simple Windows Form
Application that connects to a MSDE Database. I was reading the thread
yesterday on this very
same subject, but it only mentioned ASP.NET Applications. Can anyone
tell me if it's a good idea
|
by: Bob |
last post by:
In our new .NET web applications, we try to limit the use of SqlConnection
to just one instance per page, even if there are multiple accesses to
various queries. The thinking behind is that this reduces the need to
getting and returning connections to the pool repeatedly if a page has
multiple calls to the DB, and each one manages its own connection. However,
this does requires more deliberate coding, like calling the...
|
by: bnob |
last post by:
Im my ASP.net project I do a lot of connection to the SQL Server
Database. I use a global variabe for my connection declare in a module
(VB.Net code behind)
All is ok but when I start a form from the default page it takes 30
seconds to show the resultat of a select request
And when, during this 30 seconds, a another user want open a another
forms from the default page, I have an error : "Connection are already
open"
|
by: Steve Richter |
last post by:
I really miss c++ ....
I have an SqlConnection object within my Web.UI.Page object. The
thinking is that the connection to the database server is opened once
when the page starts to do its thing, then when everything is rendered
down to the browser, and all references to the page object are ended,
the connection to the server can be closed.
First of all, are the SqlConnection Open and Close methods quick
performers and I dont need to...
| |
by: Victor |
last post by:
Hi Guys I have a problem here.
I want to improve the performance for a website. When I looked into the
system, I have found that the system made the "SqlConnection Object" static.
That mean only one SqlConnection object will be used.
Can someone tell me is that a correct way to do? Does that affect the system
performance?
Cheers
Victor
|
by: fniles |
last post by:
I am using VB.NET 2003. When using SQLClient.SQLConnection with SQL 2005
database,
1. connection pooling is automatically used, right ? I mean, in the
connection string I do not need to explicitly write Pooling=true ?
2. What is the default Max Pool size ? After I open the connection, how can
I check what is the max pool size ?
3. I always open the db right before I fill dataset or open a reader, then
close it right away, but sometimes I...
|
by: Martin Arvidsson, Visual Systems AB |
last post by:
Hi!
I am currently developing my first webapplication using .net (2.x)
In a couple examples seen in the helpfile that came with VS2008
i see that they are opening a connection to the sql server.
Issue a command or two, then close the connection.
My question is, wouldn't it be better to have One connection open during the
current session and when the session end, close the connection.
|
by: Scott M. |
last post by:
Many methods return objects when they are called. With Excel these objects
are placed in memory and must be destroyed via ReleaseComObject as you have
done with your NAR method, but the line:
objExcel.Workbooks.Open(Page.MapPath("reports\BLCost.xls"))
could be the culprit since the Open method returns a reference to a Workbook
object that you haven't assigned a variable to. Since you have no variable
to explicitly use to destroy the...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |