473,770 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

more than one page needs connection to DB

Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.
Nov 19 '05 #1
10 1446
You can create the connection in your Session_Start event in global.asax. I
am curious, though, why you need to maintain the connection throughout the
session. That will severely limit the scalability of your application.

DalePres
MCAD, MCDBA, MCSE

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.

Nov 19 '05 #2
You can create the connection in your Session_Start event in global.asax. I
am curious, though, why you need to maintain the connection throughout the
session. That will severely limit the scalability of your application.

DalePres
MCAD, MCDBA, MCSE

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.

Nov 19 '05 #3
And one thing I left out of my last reply. After creating the connection,
you will have to save it to a session variable.

This won't work if you use a StateServer or SQL Server for session state
because only serializable objects can be maintained in state in those two
environments.

DalePres

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.

Nov 19 '05 #4
And one thing I left out of my last reply. After creating the connection,
you will have to save it to a session variable.

This won't work if you use a StateServer or SQL Server for session state
because only serializable objects can be maintained in state in those two
environments.

DalePres

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.

Nov 19 '05 #5
Store your database connection string in your web.config file, like this:

<configuratio n>
<appSettings>

<add key="DSN" value="Server=( local);Database =DBName;UID=sa; PWD="/><add
key="OtherConne ctionString"
value="Server=( local);Database =DBName2;UID=sa ;PWD="/>

</appSettings>
</configuration>

This is a nice way to manage it. You can change the connection string easily
without recompiling the app or restarting IIS or anything, and the change
goes into effect immediately.

Then in your code behinds you can get the connection string like this:
Dim sConn As String = ConfigurationSe ttings.AppSetti ngs("DSN")

You'll want to put that line on every page that does data access. Open the
connection just before you need it and close it as soon as you are done with
it. Automatic connection pooling in ADO.NET makes this a very efficient
technique.

Do not store an open connection across pages. This will severely limit the
scalability of your web site and inhibit the automatic connection pooling
from doing its job efficiently.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.

Nov 19 '05 #6
Store your database connection string in your web.config file, like this:

<configuratio n>
<appSettings>

<add key="DSN" value="Server=( local);Database =DBName;UID=sa; PWD="/><add
key="OtherConne ctionString"
value="Server=( local);Database =DBName2;UID=sa ;PWD="/>

</appSettings>
</configuration>

This is a nice way to manage it. You can change the connection string easily
without recompiling the app or restarting IIS or anything, and the change
goes into effect immediately.

Then in your code behinds you can get the connection string like this:
Dim sConn As String = ConfigurationSe ttings.AppSetti ngs("DSN")

You'll want to put that line on every page that does data access. Open the
connection just before you need it and close it as soon as you are done with
it. Automatic connection pooling in ADO.NET makes this a very efficient
technique.

Do not store an open connection across pages. This will severely limit the
scalability of your web site and inhibit the automatic connection pooling
from doing its job efficiently.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.

Nov 19 '05 #7
I understood Carlos couldn't use web.config since he gets user name and
password from the user on the start-up page.

And probably he doesn't mean keeping open connections across the pages.
Rather connection strings. Once the user is validated, the connection string
can be stored in a session variable.

Eliyahu

"Steve C. Orr [MVP, MCSD]" <St***@Orr.ne t> wrote in message
news:Oy******** ******@TK2MSFTN GP09.phx.gbl...
Store your database connection string in your web.config file, like this:

<configuratio n>
<appSettings>

<add key="DSN" value="Server=( local);Database =DBName;UID=sa; PWD="/><add
key="OtherConne ctionString"
value="Server=( local);Database =DBName2;UID=sa ;PWD="/>

</appSettings>
</configuration>

This is a nice way to manage it. You can change the connection string easily without recompiling the app or restarting IIS or anything, and the change
goes into effect immediately.

Then in your code behinds you can get the connection string like this:
Dim sConn As String = ConfigurationSe ttings.AppSetti ngs("DSN")

You'll want to put that line on every page that does data access. Open the
connection just before you need it and close it as soon as you are done with it. Automatic connection pooling in ADO.NET makes this a very efficient
technique.

Do not store an open connection across pages. This will severely limit the scalability of your web site and inhibit the automatic connection pooling
from doing its job efficiently.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.


Nov 19 '05 #8
I understood Carlos couldn't use web.config since he gets user name and
password from the user on the start-up page.

And probably he doesn't mean keeping open connections across the pages.
Rather connection strings. Once the user is validated, the connection string
can be stored in a session variable.

Eliyahu

"Steve C. Orr [MVP, MCSD]" <St***@Orr.ne t> wrote in message
news:Oy******** ******@TK2MSFTN GP09.phx.gbl...
Store your database connection string in your web.config file, like this:

<configuratio n>
<appSettings>

<add key="DSN" value="Server=( local);Database =DBName;UID=sa; PWD="/><add
key="OtherConne ctionString"
value="Server=( local);Database =DBName2;UID=sa ;PWD="/>

</appSettings>
</configuration>

This is a nice way to manage it. You can change the connection string easily without recompiling the app or restarting IIS or anything, and the change
goes into effect immediately.

Then in your code behinds you can get the connection string like this:
Dim sConn As String = ConfigurationSe ttings.AppSetti ngs("DSN")

You'll want to put that line on every page that does data access. Open the
connection just before you need it and close it as soon as you are done with it. Automatic connection pooling in ADO.NET makes this a very efficient
technique.

Do not store an open connection across pages. This will severely limit the scalability of your web site and inhibit the automatic connection pooling
from doing its job efficiently.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net

"Carlos" <ch******@yahoo .com> wrote in message
news:%2******** ********@TK2MSF TNGP15.phx.gbl. ..
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates. I have already validated
my DB connection and some operations on the start-up page, but I am not
sure
how to make the same persist
in the code behind for the other pages using C#. I appreciate any help.

Thanks,

Carlos.


Nov 19 '05 #9
Carlos wrote:
Hi all,

I am currently working on a project that needs to
maintain the connection to the DB throughout the
pages that the user navigates.


Why? This will never scale. That's why connection pools exist...

Cheers,
--
http://www.joergjooss.de
mailto:ne****** **@joergjooss.d e
Nov 19 '05 #10

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

Similar topics

21
3922
by: Rabbit63 | last post by:
Hi: I want to show a set of records in the database table on the clicnt browser. I have two ways to do this (writen in JScript): 1.The first way is: <% var sql = "select firstname from table1"; var obj=new ActiveXObject("ADODB.Recordset");
8
2062
by: DP | last post by:
I read some articles and post how to optimize te speed of asp pages regarding opening and closing DB connections but I am still not sure about this. Is it true that it doesn't matter how many times I open and destroy a DB connection on 1 single page? ---------------------------------------------------------- Set DataConn = Server.CreateObject("ADODB.Connection") Call DataConn.Open (...)
2
2357
by: Christopher Ambler | last post by:
I'm wondering if there's a solution here - I have an ASPX page with a sole purpose of scaling an image. The ASPX page contains a single line with the codebehind tag, and the .cs file contains the code to read an image, use GDI+ to scale it to a reasonable size, and emit the image directly (setting content-type on the response and spitting out the bytes for the image). What I'd love to do would be to eliminate the ASPX page and be able...
0
274
by: Carlos | last post by:
Hi all, I am currently working on a project that needs to maintain the connection to the DB throughout the pages that the user navigates. I have already validated my DB connection and some operations on the start-up page, but I am not sure how to make the same persist in the code behind for the other pages using C#. I appreciate any help. Thanks,
13
2380
by: urs | last post by:
Hi, please look at the site http://www.prismatest.ch/catalog/EM.ASPX (user=prismashop, password=minicooper). When paginating through the list, the page rebuilds itself every time on firefox and IE6. On most other sites, the browser just redraws the changing areas. Does anyone know why this is happing? I used lots of DIVs and SPANs and stayed away from TABLEs where not appropriate (except for the title bar). I also use lots of CSS. Is...
5
2828
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
We have a page that is loading very slow. There is not a lot of data, not a lot of users are connected at the same time and the page does not produce an error, so I am not sure where to start to look for why it is slowing down. I thought about the DB first and added NOLOCK to a couple of stored procedures that were being run, but with no effect. Can someone offer some tips on where to start looking or how I can begin to diagnose this...
8
1939
by: sgottenyc | last post by:
Hello, If you could assist me with the following situation, I would be very grateful. In my current position, we have to use a non-traditional server setup to serve PHP-generated web pages. Instead of the classic web server->database server setup, what they have at my workplace instead is: Apache on a frontend server -needing to connect to IIS on a backend server -needing to connect to SQL Server on the same backend server. This setup...
3
3757
by: Heggr | last post by:
I am working on creating a new ASP page that needs to populate a Select object after three other fields have been populated. I am calling a VBScript subroutine to do this from the OnClick for the specified Select object. The problem I am having is that the code will not create the ADODB Connection. I know the username and password work and if I were to create the connection in the main body of loading the page it would connect. From...
0
4608
by: AxleWacl | last post by:
Hi, The below error is what I am receiving. The code im using is below the error, for the life of me, I can not see where any parameter is missing..... Server Error in '/FleetcubeNews' Application. -------------------------------------------------------------------------------- No value given for one or more required parameters. Description: An unhandled exception occurred during the execution of the current web request. Please...
0
9453
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
10099
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
10036
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
9904
tracyyun
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...
0
8929
agi2029
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...
1
7451
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6710
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
5481
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.