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

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 "SetDefaultConnectionString" 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.Redirect("DefaultEmployee.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
connectionstring 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_start and didn't work.

Help please.
Nov 18 '05 #1
5 1636
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****@libertysurf.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 "SetDefaultConnectionString" 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.Redirect("DefaultEmployee.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
connectionstring 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_start 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****@libertysurf.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 "SetDefaultConnectionString" 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.Redirect("DefaultEmployee.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
connectionstring 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_start and didn't work.

Help please.

Nov 18 '05 #3
"Saulot" <sa****@libertysurf.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.com> wrote in message
news:b9***************@news-1.opaltelecom.net...
"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
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...
4
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...
5
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...
4
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...
12
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"...
4
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,...
14
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 _...
20
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...
4
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...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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...

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.