Ask a Question related to ASP.NET General, Design and Development.
-
Faisal #1
using static objects (declared in global.asax) in webforms
Hi.
I'm in the process of moving an application from ASP to ASP.NET, & I'm
writing in VB, using VS.NET. I'm new to the .NET framework & have a
basic question regarding static objects defined in global.asax.
In the global.asax file I want to declare some static objects (like an
ADODB.Connection, an ADODB.Recordset, a
Scripting.FileSystemObject...), and so I've done so using object tags.
For example I have:
<object runat=server id=DBConn progid="ADODB.Connection
scope=session />
So this should add DBConn to the StaticObjects collection in
HttpApplicationState, and should add DBConn to the namespace of all
the other aspx pages in the application. My problem, though, is when
I refer to any of these static objects in later pages I get build
errors. For example in the code behind page, WebForm1.aspx.vb, if I
write a statement like adcn.Open(...), I get the error: Name 'adcn' is
not declared. Am I making a mistake somewhere here? Is there
something wrong with my syntax? Or do I need to import any specific
files (so far WebForm1.aspx.vb imports ADODB, Scripting, System,
System.Web, & System.Web.UI.HtmlControls)?
I've tried instead doing things like: Application("adcn"), but I don't
think I should need to do this as adcn should already be present in
the namespace. I've alternatively tried to declare the variables
inside the sub Appliation_Start instead of using <object> tags.
However, then I try that like Glboal.adcn.open(...) I get errors
saying something like I must create an object reference first.
I think this must be a trivial question, but I can't seem to find the
answer in my searches online. Any help would be appreciated.
Thanks in advance,
Faisal
Faisal Guest
-
global.asax
Hi all! I've created a simple aspx application and when I run it locally on my pc all works fine. If I move it on the web server I get the... -
Global.asax Inheritance?
I understand how Web.Config inheritance works between a parent application and sub applications under the parent. But what I was wondering was if... -
Global Error handling in Applicatio_Error() of Global.asax
Hi all, For a web application if we are using web farm, and if i want to do Global Error handling can i use Applicatio_Error() method in... -
What is Global.asax?
It's the class file definition code for the Session and Application events - if you have anything that should be done when a user first connects or... -
accessing Global.asax design time objects
hi, how to access to Global.asax design time objects from my asp.net page? thanks in advance ..Javier Ros. -
Faisal #2
using static objects (declared in global.asax) in webforms
Sorry for the double post, but I noticed some confusing
typos in my first post (sorry). So here is a typo-free
version of my question:
--------------
Hi.
I'm in the process of moving an application from ASP to
ASP.NET, & I'm writing in VB, using VS.NET. I'm new to
the .NET framework & have a basic question regarding
static objects defined in global.asax.
In the global.asax file I want to declare some static
objects (like an ADODB.Connection, an ADODB.Recordset, a
Scripting.FileSystemObject...), and so I've done so using
object tags. For example I have:
<object runat=server id=DBConn
progid="ADODB.Connection scope=application />
So this should add DBConn to the StaticObjects collection
in HttpApplicationState, and should add DBConn to the
namespace of all the other aspx pages in the application.
My problem, though, is when I refer to any of these static
objects in later pages I get build errors. For example in
the code behind page, WebForm1.aspx.vb, if I write a
statement like DBConn.Open(...), I get the error:
Name 'DBConn' is not declared. Am I making a mistake
somewhere here? Is there something wrong with my syntax?
Or do I need to import any specific files (so far
WebForm1.aspx.vb imports ADODB, Scripting, System,
System.Web, & System.Web.UI.HtmlControls)?
I've tried instead doing things like: Application
("DBConn"), but I don't think I should need to do this as
adcn should already be present in the namespace. I've
alternatively tried to declare the variables inside the
sub Appliation_Start instead of using <object> tags.
However, then I try that like Global.DBConn.open(...) I
get errors saying something like I must create an object
reference first.
I think this must be a trivial question, but I can't seem
to find the answer in my searches online. Any help would
be appreciated.
Thanks in advance,
Faisal
Faisal Guest
-
Kevin Spencer #3
Re: using static objects (declared in global.asax) in webforms
First of all, you shouldn't be using ADODB. Use the appropriate managed
classes instead, from the System.Data namespace. Secondly, caching
Connections has NEVER been a good idea, and is especially so with ASP.Net,
as the .Net Framework fully leverages Connection Pooling, and ADO.Net
doesn't work much like ADODB internally.
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
[url]http://www.takempis.com[/url]
Complex things are made up of
lots of simple things.
"Faisal" <ftajdar@yahoo.com> wrote in message
news:1340e3d1.0307292120.31c1b230@posting.google.c om...> Hi.
>
> I'm in the process of moving an application from ASP to ASP.NET, & I'm
> writing in VB, using VS.NET. I'm new to the .NET framework & have a
> basic question regarding static objects defined in global.asax.
>
> In the global.asax file I want to declare some static objects (like an
> ADODB.Connection, an ADODB.Recordset, a
> Scripting.FileSystemObject...), and so I've done so using object tags.
> For example I have:
> <object runat=server id=DBConn progid="ADODB.Connection
> scope=session />
>
> So this should add DBConn to the StaticObjects collection in
> HttpApplicationState, and should add DBConn to the namespace of all
> the other aspx pages in the application. My problem, though, is when
> I refer to any of these static objects in later pages I get build
> errors. For example in the code behind page, WebForm1.aspx.vb, if I
> write a statement like adcn.Open(...), I get the error: Name 'adcn' is
> not declared. Am I making a mistake somewhere here? Is there
> something wrong with my syntax? Or do I need to import any specific
> files (so far WebForm1.aspx.vb imports ADODB, Scripting, System,
> System.Web, & System.Web.UI.HtmlControls)?
>
> I've tried instead doing things like: Application("adcn"), but I don't
> think I should need to do this as adcn should already be present in
> the namespace. I've alternatively tried to declare the variables
> inside the sub Appliation_Start instead of using <object> tags.
> However, then I try that like Glboal.adcn.open(...) I get errors
> saying something like I must create an object reference first.
>
> I think this must be a trivial question, but I can't seem to find the
> answer in my searches online. Any help would be appreciated.
>
> Thanks in advance,
> Faisal
Kevin Spencer Guest
-
Faisal #4
Re: using static objects (declared in global.asax) in webforms
Hi Kevin,
Thanks for your advice; I'm reading up on using ADO.NET
and moving way from ADODB as you suggested. Can you (or
anyone else) suggest some links where I can read up on
connection pooling?
Secondly, since the .NET framework does support ADO, if I
wanted to initially just move my web application from ASP
to ASP.NET by making the minimal amount of changes, do you
see a way I can fix my problem? I recognize that I should
work on implementing classes from System.Data & System.IO
instead of ADODB & Scripting to get the most out of .NET.
However, since I'm new at most of this, and I figure that
an easier strategy for me would be to first work on simply
getting the web application up & running in .NET, and then
go back to make the changes wrt the way I'm doing database
interaction & file I/O.
With that said, I've been trying initially just to move
stuff from global.asa to global.asax, and am still rather
confused why the static objects are not recongized in all
my .aspx.vb files. Any ideas on that?
Many thanks,
-Faisal
appropriate managed>-----Original Message-----
>First of all, you shouldn't be using ADODB. Use theSecondly, caching>classes instead, from the System.Data namespace.so with ASP.Net,>Connections has NEVER been a good idea, and is especiallyand ADO.Net>as the .Net Framework fully leverages Connection Pooling,ASP.NET, & I'm>doesn't work much like ADODB internally.
>
>--
>HTH,
>
>Kevin Spencer
>Microsoft MVP
>..Net Developer
>[url]http://www.takempis.com[/url]
>Complex things are made up of
>lots of simple things.
>
>"Faisal" <ftajdar@yahoo.com> wrote in message
>news:1340e3d1.0307292120.31c1b230@posting.google. com...>> Hi.
>>
>> I'm in the process of moving an application from ASP toframework & have a>> writing in VB, using VS.NET. I'm new to the .NETglobal.asax.>> basic question regarding static objects defined inobjects (like an>>
>> In the global.asax file I want to declare some staticusing object tags.>> ADODB.Connection, an ADODB.Recordset, a
>> Scripting.FileSystemObject...), and so I've done soprogid="ADODB.Connection>> For example I have:
>> <object runat=server id=DBConncollection in>> scope=session />
>>
>> So this should add DBConn to the StaticObjectsnamespace of all>> HttpApplicationState, and should add DBConn to thethough, is when>> the other aspx pages in the application. My problem,get build>> I refer to any of these static objects in later pages IWebForm1.aspx.vb, if I>> errors. For example in the code behind page,Name 'adcn' is>> write a statement like adcn.Open(...), I get the error:Is there>> not declared. Am I making a mistake somewhere here?any specific>> something wrong with my syntax? Or do I need to importScripting, System,>> files (so far WebForm1.aspx.vb imports ADODB,("adcn"), but I don't>> System.Web, & System.Web.UI.HtmlControls)?
>>
>> I've tried instead doing things like: Applicationbe present in>> think I should need to do this as adcn should alreadyvariables>> the namespace. I've alternatively tried to declare the<object> tags.>> inside the sub Appliation_Start instead of usingget errors>> However, then I try that like Glboal.adcn.open(...) Ifirst.>> saying something like I must create an object referenceseem to find the>>
>> I think this must be a trivial question, but I can'tappreciated.>> answer in my searches online. Any help would be>>>
>> Thanks in advance,
>> Faisal
>
>.
>Faisal Guest



Reply With Quote

