N
Natan
Hi,
I`m creating a asp.net intranet system, and would like to put all the
logic of the system in a single dll. That is, when i need to create an
user for example, i would use "User.Check()" and "User.Add()" instead of
putting "insert" sql statements in the page.
Considering he following logic:
User u = new User();
u.Name = "John Doe";
u.Email = "(e-mail address removed)";
u.Login = "john";
u.Pass = "blah";
if (!User.Exists(u) and User.IsValid(u))
User.Add(u);
User.Exists checks if there is a user with that login, User.IsValid
checks to see if the name and other data is valid.. and User.Add adds
the user to the database. All the three methods access the database and
i'm creating a method that will return this database connection.
My question is: What is the best practice? Should i create a method to
return a new SqlConnection object, open and close that conection in each
method i use it, or create a property that returns a static opened
connection? Even with connection pooling, i think there is a better way
to do things than opening and closing a connection 5 or 6 times in a
single page.
Other idea was open a single static connection once, let`s say in
global.asax and using it for every everywhere. Is there any problem with
this?
Thanks.
I`m creating a asp.net intranet system, and would like to put all the
logic of the system in a single dll. That is, when i need to create an
user for example, i would use "User.Check()" and "User.Add()" instead of
putting "insert" sql statements in the page.
Considering he following logic:
User u = new User();
u.Name = "John Doe";
u.Email = "(e-mail address removed)";
u.Login = "john";
u.Pass = "blah";
if (!User.Exists(u) and User.IsValid(u))
User.Add(u);
User.Exists checks if there is a user with that login, User.IsValid
checks to see if the name and other data is valid.. and User.Add adds
the user to the database. All the three methods access the database and
i'm creating a method that will return this database connection.
My question is: What is the best practice? Should i create a method to
return a new SqlConnection object, open and close that conection in each
method i use it, or create a property that returns a static opened
connection? Even with connection pooling, i think there is a better way
to do things than opening and closing a connection 5 or 6 times in a
single page.
Other idea was open a single static connection once, let`s say in
global.asax and using it for every everywhere. Is there any problem with
this?
Thanks.