Hello,
I'm just starting to develop in asp.net and i have a question about
using a database connection globally in my app. I have set up the
procedures for getting all my connection string info which each page
will use, but my question relates to how to use the database
connection i create in all my classes.
I have a database class, in a separate namespace and file, i created
that handles all the connection opening, executing statements etc. I
also use 2 other classes in my asp.net app. which are in the same
namespace and same file.
1 holds information specific to the current user logged in, and the
other class is used as a global functions class. I want to be able to
open the db connection once, and no matter if i'm running a method in
the UserSession class, or the Global Functions class to be able to use
that same Database class i created, without creating a new instance of
the database class in each class i want to run this in.
example. my UserSession class might have the web login authentication
method in it that gets run when the user clicks the login button on
the login page, right after that method runs, which again is in the
user session class, i might run a method from the global functions
class that needs to use the database. i wanted to use the same
Database class i instantiated instead of creating a separate instance
of the database class for each class i needed it in. Can this be done?
or do i need to change my thinking around a little and use a different
model.
thanks for any help you can offer. Any links to any "best practice"
type info/articles would be appreciated as well.
Bryan