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

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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.
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

    >-----Original Message-----
    >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. com...
    >> 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139