using static objects (declared in global.asax) in webforms

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 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.Connectio n, an ADODB.Recordset , a
    Scripting.FileS ystemObject...) , and so I've done so using object tags.
    For example I have:
    <object runat=server id=DBConn progid="ADODB.C onnection
    scope=session />

    So this should add DBConn to the StaticObjects collection in
    HttpApplication State, 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.v b, 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.v b imports ADODB, Scripting, System,
    System.Web, & System.Web.UI.H tmlControls)?

    I've tried instead doing things like: Application("ad cn"), 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_Star t instead of using <object> tags.
    However, then I try that like Glboal.adcn.ope n(...) 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

    #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.Connectio n, an ADODB.Recordset , a
    Scripting.FileS ystemObject...) , and so I've done so using
    object tags. For example I have:
    <object runat=server id=DBConn
    progid="ADODB.C onnection scope=applicati on />

    So this should add DBConn to the StaticObjects collection
    in HttpApplication State, 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.v b, 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.v b imports ADODB, Scripting, System,
    System.Web, & System.Web.UI.H tmlControls)?

    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_Star t instead of using <object> tags.
    However, then I try that like Global.DBConn.o pen(...) 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

    Comment

    • 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
      All hotels in Benidorm. The best selection of Benidorm hotels with reviews and maps. Book in advance and save.

      Complex things are made up of
      lots of simple things.

      "Faisal" <ftajdar@yahoo. com> wrote in message
      news:1340e3d1.0 307292120.31c1b 230@posting.goo gle.com...[color=blue]
      > 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.Connectio n, an ADODB.Recordset , a
      > Scripting.FileS ystemObject...) , and so I've done so using object tags.
      > For example I have:
      > <object runat=server id=DBConn progid="ADODB.C onnection
      > scope=session />
      >
      > So this should add DBConn to the StaticObjects collection in
      > HttpApplication State, 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.v b, 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.v b imports ADODB, Scripting, System,
      > System.Web, & System.Web.UI.H tmlControls)?
      >
      > I've tried instead doing things like: Application("ad cn"), 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_Star t instead of using <object> tags.
      > However, then I try that like Glboal.adcn.ope n(...) 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[/color]


      Comment

      • 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

        [color=blue]
        >-----Original Message-----
        >First of all, you shouldn't be using ADODB. Use the[/color]
        appropriate managed[color=blue]
        >classes instead, from the System.Data namespace.[/color]
        Secondly, caching[color=blue]
        >Connections has NEVER been a good idea, and is especially[/color]
        so with ASP.Net,[color=blue]
        >as the .Net Framework fully leverages Connection Pooling,[/color]
        and ADO.Net[color=blue]
        >doesn't work much like ADODB internally.
        >
        >--
        >HTH,
        >
        >Kevin Spencer
        >Microsoft MVP
        >..Net Developer
        >http://www.takempis.com
        >Complex things are made up of
        >lots of simple things.
        >
        >"Faisal" <ftajdar@yahoo. com> wrote in message
        >news:1340e3d1. 0307292120.31c1 b230@posting.go ogle.com...[color=green]
        >> Hi.
        >>
        >> I'm in the process of moving an application from ASP to[/color][/color]
        ASP.NET, & I'm[color=blue][color=green]
        >> writing in VB, using VS.NET. I'm new to the .NET[/color][/color]
        framework & have a[color=blue][color=green]
        >> basic question regarding static objects defined in[/color][/color]
        global.asax.[color=blue][color=green]
        >>
        >> In the global.asax file I want to declare some static[/color][/color]
        objects (like an[color=blue][color=green]
        >> ADODB.Connectio n, an ADODB.Recordset , a
        >> Scripting.FileS ystemObject...) , and so I've done so[/color][/color]
        using object tags.[color=blue][color=green]
        >> For example I have:
        >> <object runat=server id=DBConn[/color][/color]
        progid="ADODB.C onnection[color=blue][color=green]
        >> scope=session />
        >>
        >> So this should add DBConn to the StaticObjects[/color][/color]
        collection in[color=blue][color=green]
        >> HttpApplication State, and should add DBConn to the[/color][/color]
        namespace of all[color=blue][color=green]
        >> the other aspx pages in the application. My problem,[/color][/color]
        though, is when[color=blue][color=green]
        >> I refer to any of these static objects in later pages I[/color][/color]
        get build[color=blue][color=green]
        >> errors. For example in the code behind page,[/color][/color]
        WebForm1.aspx.v b, if I[color=blue][color=green]
        >> write a statement like adcn.Open(...), I get the error:[/color][/color]
        Name 'adcn' is[color=blue][color=green]
        >> not declared. Am I making a mistake somewhere here?[/color][/color]
        Is there[color=blue][color=green]
        >> something wrong with my syntax? Or do I need to import[/color][/color]
        any specific[color=blue][color=green]
        >> files (so far WebForm1.aspx.v b imports ADODB,[/color][/color]
        Scripting, System,[color=blue][color=green]
        >> System.Web, & System.Web.UI.H tmlControls)?
        >>
        >> I've tried instead doing things like: Application[/color][/color]
        ("adcn"), but I don't[color=blue][color=green]
        >> think I should need to do this as adcn should already[/color][/color]
        be present in[color=blue][color=green]
        >> the namespace. I've alternatively tried to declare the[/color][/color]
        variables[color=blue][color=green]
        >> inside the sub Appliation_Star t instead of using[/color][/color]
        <object> tags.[color=blue][color=green]
        >> However, then I try that like Glboal.adcn.ope n(...) I[/color][/color]
        get errors[color=blue][color=green]
        >> saying something like I must create an object reference[/color][/color]
        first.[color=blue][color=green]
        >>
        >> I think this must be a trivial question, but I can't[/color][/color]
        seem to find the[color=blue][color=green]
        >> answer in my searches online. Any help would be[/color][/color]
        appreciated.[color=blue][color=green]
        >>
        >> Thanks in advance,
        >> Faisal[/color]
        >
        >
        >.
        >[/color]

        Comment

        Working...