473,405 Members | 2,171 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,405 software developers and data experts.

re-using c# code in asp.net with minimal resources

Please take your time to read the following, it's simple although the text
is 3 paragraphs...

Everytime an user is logged in I need to make a call to my sql server
database to grab some specific user settings and load into Session
variables. So, I have a "Loggedin" event in login.aspx which does this. As
users can be logged in (automatically) via HttpApplication & Cookies, I need
to run this same code after that. I can put the same code as above in this
particular event handler in my global.asax code but I want to have this code
stored in only one place although called from the above mentioned two
situations.

1) I store the custom code in global.asax, create a new global_asax class
from the login.aspx code and call the method. This means that every time an
user is logged in I have eaten up unneccesary amount of resources since the
new global_asax class resides in memory until destroyed (especially since
the code creates both SqlConnection and SqlDataReader objects). Also I'm
afraid I could run into thread-level clashes in case multiple requests are
using the global_asax code at same time (the SqlDataReader for example is
very sensitive here).
2) I have a custom "code" class e.g. "commons.cs" in my App_Code folder and
from global.asax and login.aspx create new instance of that class and call
the code. The same as above: this uses a lot of resources compared to a very
simple task.
....

I hope you get my point! Any ideas on how to solve this "smoothly", using
minimal resources and without storing the code.
Jan 11 '06 #1
3 1657
Daves,

You should go with #2. I don't understand why you think that uses a
good deal of resources. It's just a class instance, and if it is not such a
complex operation, you can always make the methods static.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daves" <db****@simnet.is> wrote in message
news:ua*************@TK2MSFTNGP15.phx.gbl...
Please take your time to read the following, it's simple although the text
is 3 paragraphs...

Everytime an user is logged in I need to make a call to my sql server
database to grab some specific user settings and load into Session
variables. So, I have a "Loggedin" event in login.aspx which does this. As
users can be logged in (automatically) via HttpApplication & Cookies, I
need to run this same code after that. I can put the same code as above in
this particular event handler in my global.asax code but I want to have
this code stored in only one place although called from the above
mentioned two situations.

1) I store the custom code in global.asax, create a new global_asax class
from the login.aspx code and call the method. This means that every time
an user is logged in I have eaten up unneccesary amount of resources since
the new global_asax class resides in memory until destroyed (especially
since the code creates both SqlConnection and SqlDataReader objects). Also
I'm afraid I could run into thread-level clashes in case multiple requests
are using the global_asax code at same time (the SqlDataReader for example
is very sensitive here).
2) I have a custom "code" class e.g. "commons.cs" in my App_Code folder
and from global.asax and login.aspx create new instance of that class and
call the code. The same as above: this uses a lot of resources compared to
a very simple task.
...

I hope you get my point! Any ideas on how to solve this "smoothly", using
minimal resources and without storing the code.

Jan 11 '06 #2
thx, feel a little more confident in using that way then. Just have this
feeling that a class instance creating a SqlConnection and SqlDataReader
would eat up kilobytes of memory and could be solved in an easier way. Btw,
is there a method to "destroy" that class again when it's been used?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP14.phx.gbl...
Daves,

You should go with #2. I don't understand why you think that uses a
good deal of resources. It's just a class instance, and if it is not such
a complex operation, you can always make the methods static.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daves" <db****@simnet.is> wrote in message
news:ua*************@TK2MSFTNGP15.phx.gbl...
Please take your time to read the following, it's simple although the
text is 3 paragraphs...

Everytime an user is logged in I need to make a call to my sql server
database to grab some specific user settings and load into Session
variables. So, I have a "Loggedin" event in login.aspx which does this.
As users can be logged in (automatically) via HttpApplication & Cookies,
I need to run this same code after that. I can put the same code as above
in this particular event handler in my global.asax code but I want to
have this code stored in only one place although called from the above
mentioned two situations.

1) I store the custom code in global.asax, create a new global_asax class
from the login.aspx code and call the method. This means that every time
an user is logged in I have eaten up unneccesary amount of resources
since the new global_asax class resides in memory until destroyed
(especially since the code creates both SqlConnection and SqlDataReader
objects). Also I'm afraid I could run into thread-level clashes in case
multiple requests are using the global_asax code at same time (the
SqlDataReader for example is very sensitive here).
2) I have a custom "code" class e.g. "commons.cs" in my App_Code folder
and from global.asax and login.aspx create new instance of that class and
call the code. The same as above: this uses a lot of resources compared
to a very simple task.
...

I hope you get my point! Any ideas on how to solve this "smoothly", using
minimal resources and without storing the code.


Jan 12 '06 #3
Daves,

Well, once you let the instance go, that's it, if there are no other
references to it, then you shouldn't have a problem. The GC will eventually
clean it up.

As for using SqlConnection and SqlDataReader, on a website especially,
you should be creating your own connection, opening it, and closing it in
your specific operation. You definitely should not be sharing an open
connection in your website.

Just make sure you dispose of the SqlConnection and SqlDataReader
correctly (using statements help here), and you should be fine.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daves" <db****@simnet.is> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
thx, feel a little more confident in using that way then. Just have this
feeling that a class instance creating a SqlConnection and SqlDataReader
would eat up kilobytes of memory and could be solved in an easier way.
Btw, is there a method to "destroy" that class again when it's been used?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Daves,

You should go with #2. I don't understand why you think that uses a
good deal of resources. It's just a class instance, and if it is not
such a complex operation, you can always make the methods static.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Daves" <db****@simnet.is> wrote in message
news:ua*************@TK2MSFTNGP15.phx.gbl...
Please take your time to read the following, it's simple although the
text is 3 paragraphs...

Everytime an user is logged in I need to make a call to my sql server
database to grab some specific user settings and load into Session
variables. So, I have a "Loggedin" event in login.aspx which does this.
As users can be logged in (automatically) via HttpApplication & Cookies,
I need to run this same code after that. I can put the same code as
above in this particular event handler in my global.asax code but I want
to have this code stored in only one place although called from the
above mentioned two situations.

1) I store the custom code in global.asax, create a new global_asax
class from the login.aspx code and call the method. This means that
every time an user is logged in I have eaten up unneccesary amount of
resources since the new global_asax class resides in memory until
destroyed (especially since the code creates both SqlConnection and
SqlDataReader objects). Also I'm afraid I could run into thread-level
clashes in case multiple requests are using the global_asax code at same
time (the SqlDataReader for example is very sensitive here).
2) I have a custom "code" class e.g. "commons.cs" in my App_Code folder
and from global.asax and login.aspx create new instance of that class
and call the code. The same as above: this uses a lot of resources
compared to a very simple task.
...

I hope you get my point! Any ideas on how to solve this "smoothly",
using minimal resources and without storing the code.



Jan 12 '06 #4

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

Similar topics

1
by: Nel | last post by:
I have a question related to the "security" issues posed by Globals ON. It is good programming technique IMO to initialise variables, even if it's just $foo = 0; $bar = ""; Surely it would...
4
by: Craig Bailey | last post by:
Anyone recommend a good script editor for Mac OS X? Just finished a 4-day PHP class in front of a Windows machine, and liked the editor we used. Don't recall the name, but it gave line numbers as...
11
by: James | last post by:
My form and results are on one page. If I use : if ($Company) { $query = "Select Company, Contact From tblworking Where ID = $Company Order By Company ASC"; }
4
by: Alan Walkington | last post by:
Folks: How can I get an /exec'ed/ process to run in the background on an XP box? I have a monitor-like process which I am starting as 'exec("something.exe");' and, of course the exec function...
8
by: Beowulf | last post by:
Hi Guru's, I have a query regarding using PHP to maintain a user profiles list. I want to be able to have a form where users can fill in their profile info (Name, hobbies etc) and attach an...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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...
0
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...
0
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,...
0
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...

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.