473,769 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Where to open connection and close it ?

Hi,
Facing a big problem.
In my Default.aspx page, I open a connection with ma Sql Server DataBase
through my objects framework (A "SetDefaultConn ectionString" property which
open my connection... work fine with winforms)
My Default.aspx page is a login one.
When I log in, no problem, I got my
Response.Redire ct("DefaultEmpl oyee.aspx") which works well. Then, I click on
another Redirect which leads me to the employee's personnal informations and
THERE, Problem.
BUT, using spy window, I can see that just after the Redirect thing, my
connectionstrin g is set to nothing !!!

So here is the point.
Is there a place to open my connection that it'll be available for the whole
pages of my site and so on, a place to close it when my user lives the site.
I tried Application_sta rt and didn't work.

Help please.
Nov 18 '05 #1
5 1659
Saulot:
You are supposed to open connections as late as possible and close them as
soon as possible. You are totally trying to do the opposite.

Also, you provided no code and no information about the actual
problem/error/exception.

OPen the connection, fill your dataset, close the connection, return the
dataset...

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Saulot" <sa****@liberty surf.fr> wrote in message
news:41******** **************@ news.free.fr...
Hi,
Facing a big problem.
In my Default.aspx page, I open a connection with ma Sql Server DataBase
through my objects framework (A "SetDefaultConn ectionString" property which open my connection... work fine with winforms)
My Default.aspx page is a login one.
When I log in, no problem, I got my
Response.Redire ct("DefaultEmpl oyee.aspx") which works well. Then, I click on another Redirect which leads me to the employee's personnal informations and THERE, Problem.
BUT, using spy window, I can see that just after the Redirect thing, my
connectionstrin g is set to nothing !!!

So here is the point.
Is there a place to open my connection that it'll be available for the whole pages of my site and so on, a place to close it when my user lives the site. I tried Application_sta rt and didn't work.

Help please.

Nov 18 '05 #2
In a web application, the page is recreated each time (if you keep the
connection string in a page member it will be reinitialized the next time as
the page just lives the time of the HTTP request).

Also you generally open/create the connection each time you need it to avoid
:
- having a unique connection for all users (it would block users majking
this single connection a bottleneck)
- haing a connection for each user (it would use a vast amount of resources)

ASP.NET uses a connection pool. When you create a connection, it is taken
from the pool. When you close it, it is returned to the pool. This way you
only need as much connections, as you have current requests executing (ie.
you could server 100 users with 10 connections).

Patrice

--

"Saulot" <sa****@liberty surf.fr> a écrit dans le message de
news:41******** **************@ news.free.fr...
Hi,
Facing a big problem.
In my Default.aspx page, I open a connection with ma Sql Server DataBase
through my objects framework (A "SetDefaultConn ectionString" property which open my connection... work fine with winforms)
My Default.aspx page is a login one.
When I log in, no problem, I got my
Response.Redire ct("DefaultEmpl oyee.aspx") which works well. Then, I click on another Redirect which leads me to the employee's personnal informations and THERE, Problem.
BUT, using spy window, I can see that just after the Redirect thing, my
connectionstrin g is set to nothing !!!

So here is the point.
Is there a place to open my connection that it'll be available for the whole pages of my site and so on, a place to close it when my user lives the site. I tried Application_sta rt and didn't work.

Help please.

Nov 18 '05 #3
"Saulot" <sa****@liberty surf.fr> wrote in message
news:41******** **************@ news.free.fr...
Is there a place to open my connection that it'll be available for the
whole
pages of my site and so on, a place to close it when my user lives the
site.


I'm struggling to think of anything worse than this for completely crippling
your site's performance!!!
Nov 18 '05 #4

"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message

Maybe if it queries a table that returns thousands of results and then binds
them server side to a datagrid without paging. That would be a start.
Is there a place to open my connection that it'll be available for the
whole
pages of my site and so on, a place to close it when my user lives the
site.
I'm struggling to think of anything worse than this for completely

crippling your site's performance!!!

Nov 18 '05 #5
"Ian Frawley" <ch****@away.co m> wrote in message
news:b9******** *******@news-1.opaltelecom.n et...
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message

Maybe if it queries a table that returns thousands of results and then
binds
them server side to a datagrid without paging. That would be a start.


LOL! Maybe if it then downloads the resultset of this query to each client's
PC for "really efficient" client-server architecture ;-) Could just query it
locally, no need for that costly round-trip to the server any more...
Nov 18 '05 #6

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

Similar topics

1
2567
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and close them as early as possible. My requirement is as follows: I'm developing a class library that will be instantiated by a COM component. My class library contains functions that perform lot of mathematical calculations and read a lot of data...
4
2472
by: Macca | last post by:
Hi, I have an windows forms application that accesses a SQL database I have a few questions as to connecting to the database. This application will run 24 hours a day. It is a monitoring application and will store events that happen in the database (These events happen randomly without pattern, between 10-50 a day) . There are a number of situations where the database is accessed.
5
1787
by: ypul | last post by:
the code below given is connection class ... now I want to use the connection in another class , by using the getConnection method. where should I call con.dispose() ? in connection class or in the caller class ? if I call con.dispose in connection class as given below ..will I be able to use the connection in the other class where I am calling this method ..or I will get a NULL connection ??
4
14893
by: James Radke | last post by:
Hello, I am attempting to use the proper Try/Catch technique when accessing my Microsoft SQL server database and have a question... If I use something similar to the following: Try set up SQL connection open the SQL connection
12
27019
by: Yannick | last post by:
Hi, I've got a problem accessing a ms-access db with a sql statement like this: SELECT * FROM laTable WHERE laDate = #05/21/2004# ; with asp.net (vb code) laTable contains a "laDate" datetime field .
4
3984
by: mescano | last post by:
I am currently implementing a singleton pattern for accessing a database. Is it advisable to close the connection to the database at all -- thus leaving it open or should it be closed. If closed, when should I it close it -- after the execution of the each command to the database? If leaving open, what impacts does it have. Imagining that it is one connection to the database. Thanks, mescano
14
4615
by: martin1 | last post by:
All, I want to check wether db connection/open or not, if not it will post db connection error to user in message box The code is like: Dim objConnection As New SqlConnection _ ("Server=server1; database=db1;user id=user1;password=whatever") Dim objDataAdapter As New SqlDataAdapter() Dim objDataSet
20
7215
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I get the error "There is already an open DataReader associated with this Connection which must be closed first." How can I fix this error ? For each DataReader, do I want to open and close the connection (in this case adoCon) to avoid this error ?...
4
3433
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.
0
9590
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
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
10223
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...
0
10051
jinu1996
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...
1
10000
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
6675
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
5310
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2815
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.