Database connection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I am facing a problem regarding setting database connection in my ASP.NET
project. I want to open a connection in a particular file(like in
global.asax.vb) and want to get the connection from all pages.
Please tell me the way (or any other better way) to open the connection once
so that I can use it (to Fill it ) from any changes further writing no
connection open code.
Regards Sudip.
 
Hi Sudip,

You really shouldn't do it this way, specially in an asp.net application as
it would kill the server (immagine having 1000 users and 1000 connections)
Instead, you should have connection opened only when you need it and close
it asap.
 
Hello,
Can I fetch the processid of a connected host and then use the processid to
kill the connection so that other connection would not be hampered? If
possible then please write me the exact code in vb.net or c#. Writing
connection open and close in each function or event as u told slowers the
page response.
Thank u very much.
Sudip

Miha Markic said:
Hi Sudip,

You really shouldn't do it this way, specially in an asp.net application as
it would kill the server (immagine having 1000 users and 1000 connections)
Instead, you should have connection opened only when you need it and close
it asap.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

Sudip said:
Hi,
I am facing a problem regarding setting database connection in my ASP.NET
project. I want to open a connection in a particular file(like in
global.asax.vb) and want to get the connection from all pages.
Please tell me the way (or any other better way) to open the connection
once
so that I can use it (to Fill it ) from any changes further writing no
connection open code.
Regards Sudip.
 
See comment inline.

Sudip said:
Hello,
Can I fetch the processid of a connected host and then use the processid to
kill the connection so that other connection would not be hampered? If
possible then please write me the exact code in vb.net or c#. Writing
connection open and close in each function or event as u told slowers the

Not so UNLESS you specifically disabled connection pooling in ADO.NET or the
database server (but why, it is web app, right?).
As Miha said, you should only only connection when absolutely needed and
close it as soon as possible. Keeping connection openning cross pages is
definitely bad practice.
page response.
Thank u very much.
Sudip

Miha Markic said:
Hi Sudip,

You really shouldn't do it this way, specially in an asp.net application as
it would kill the server (immagine having 1000 users and 1000 connections)
Instead, you should have connection opened only when you need it and close
it asap.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/
SLODUG - Slovene Developer Users Group www.codezone-si.info

Sudip said:
Hi,
I am facing a problem regarding setting database connection in my ASP.NET
project. I want to open a connection in a particular file(like in
global.asax.vb) and want to get the connection from all pages.
Please tell me the way (or any other better way) to open the connection
once
so that I can use it (to Fill it ) from any changes further writing no
connection open code.
Regards Sudip.
 
Back
Top