473,387 Members | 1,456 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,387 software developers and data experts.

better approaches

which one is better approach among the two listed below

1. Opening connection on each web page for doing some database transaction

2. Opening connection once and store it in application object, and then
refering this application object on each web page.

Thanks
Nov 18 '05 #1
6 1021
dear vicky
both r wrong
store ur connectn string always in the web.config files
as
<appSettings>

<add key="anyname" value="Data source=xyz;initial catalog=DBNAME;user
ed=sa;password=sa"/>

<add key="TimeOut" value="10"/>

</appSettings>
--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
"Vicky" <vi*********@rediffmail.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
which one is better approach among the two listed below

1. Opening connection on each web page for doing some database transaction

2. Opening connection once and store it in application object, and then
refering this application object on each web page.

Thanks

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.574 / Virus Database: 364 - Release Date: 1/29/2004
Nov 18 '05 #2
I think u misinterpreted by question, i mean not connection string but
instance of open connection object connected to a Sql server database

thanks
".NET Follower" <am*************@SoftHome.net> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
dear vicky
both r wrong
store ur connectn string always in the web.config files
as
<appSettings>

<add key="anyname" value="Data source=xyz;initial catalog=DBNAME;user
ed=sa;password=sa"/>

<add key="TimeOut" value="10"/>

</appSettings>
--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
"Vicky" <vi*********@rediffmail.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
which one is better approach among the two listed below

1. Opening connection on each web page for doing some database transaction
2. Opening connection once and store it in application object, and then
refering this application object on each web page.

Thanks

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.574 / Virus Database: 364 - Release Date: 1/29/2004

Nov 18 '05 #3
I think generally, it's better to open the connection, do your database
stuff, and then close the connection on each page. As far as I know, the
connnection pooling and optimisation stuff is done by the .net framework and
windows.

Mun
--
Munsifali Rashid
http://www.munsplace.com/


"Vicky" <vi*********@rediffmail.com> wrote in message
news:Oj****************@tk2msftngp13.phx.gbl...
I think u misinterpreted by question, i mean not connection string but
instance of open connection object connected to a Sql server database

thanks

Nov 18 '05 #4
Option (3) ;)

You should use a connection and then close it when you no longer need it. If
you have a group of calls you want to make, you can open the connection and
live it open until the rest of the steps are complete (as long as there is
no collision on the connection), but it is best if this time frame is short,
you would not want to leave connections open past the duration of the page
request. In this way you allow the ADO.NET handling of connection pooling
to function.

If you are using datasets, simply allow the adapter to open and close the
connections as required.

As a side note, make sure you close all your datareaders when you are
finished with them (if you use them at all).

--
Rocky Moore
www.HintsAndTips.com - Share your tips with the world!
~~~~~~~~~ Developer Tips Welcome! ~~~~~~~~~

"Vicky" <vi*********@rediffmail.com> wrote in message
news:#M**************@TK2MSFTNGP09.phx.gbl...
which one is better approach among the two listed below

1. Opening connection on each web page for doing some database transaction

2. Opening connection once and store it in application object, and then
refering this application object on each web page.

Thanks

Nov 18 '05 #5
ya
i misinterprated ur ?

it is always a better practise to open and close ur DB connectn
immediately on every page.
imagine numerous clients opening a connection to DB
so how much resources is blocked
and so ur app will definately crash.

some objects like the dataadapter does itself this job

however for Action queries like ExecuteNONQuery etc
u hv to xplicitly open and close connectn s

so 1 is recommended.

--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
".NET Follower" <am*************@SoftHome.net> wrote in message
news:uI****************@tk2msftngp13.phx.gbl...
dear vicky
both r wrong
store ur connectn string always in the web.config files
as
<appSettings>

<add key="anyname" value="Data source=xyz;initial catalog=DBNAME;user
ed=sa;password=sa"/>

<add key="TimeOut" value="10"/>

</appSettings>
--
Thanks and Regards,

Amit Agarwal
Software Programmer(.NET)
"Vicky" <vi*********@rediffmail.com> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
which one is better approach among the two listed below

1. Opening connection on each web page for doing some database transaction
2. Opening connection once and store it in application object, and then
refering this application object on each web page.

Thanks

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.574 / Virus Database: 364 - Release Date: 1/29/2004

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.574 / Virus Database: 364 - Release Date: 1/29/2004
Nov 18 '05 #6
Thanks, i too was doing this only.

"Munsifali Rashid" <mun.news@#RemoveToReply#cordlessmouse.co.uk> wrote in
message news:uV**************@TK2MSFTNGP10.phx.gbl...
I think generally, it's better to open the connection, do your database
stuff, and then close the connection on each page. As far as I know, the
connnection pooling and optimisation stuff is done by the .net framework and windows.

Mun
--
Munsifali Rashid
http://www.munsplace.com/


"Vicky" <vi*********@rediffmail.com> wrote in message
news:Oj****************@tk2msftngp13.phx.gbl...
I think u misinterpreted by question, i mean not connection string but
instance of open connection object connected to a Sql server database

thanks


Nov 18 '05 #7

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

Similar topics

133
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
24
by: markscala | last post by:
Problem: You have a list of unknown length, such as this: list = . You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is...
2
by: Damien | last post by:
Hi all, I'm messing around with various signal/slot mechanisms, trying to build something lean and fast. I've used libsigc++, and Sarah Thompson's at sigslot.sourceforge.net, and most of the...
2
by: zefciu | last post by:
In the tutorial there is an example iterator class that revesrses the string given to the constructor. The problem is that this class works only once, unlike built-in types like string. How to...
3
by: =?Utf-8?B?Um9sYW5kcGlzaA==?= | last post by:
Hi, I'm doing an application using C# and I have this question: I have a method called sqlQueryBD which receives a string sql query and executes it against a database. I also have a class called...
1
by: qbob | last post by:
I have data that is essentially tree-like, and to store it/iterate over it I have been using nested dictionaries, eg: Dictionary<int, Dictionary<string, Dictionary<double>>> data = new ... to...
20
by: mike3 | last post by:
Hi. (Xposted to both comp.lang.c++ and comp.programming since I've got questions related to both C++ language and general programming) I've got the following C++ code. The first routine runs in...
13
by: S James S Stapleton | last post by:
I have some code, and I want to make it future-resistant. I have a bunch of variables that are set up run-time, and once set up, should act as constants. I don't want to #define them, because their...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.