Results 1 to 9 of 9

Thread: [2005] Best practices and Modules question

  1. #1

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    [2005] Best practices and Modules question

    I am new to ASP.Net 2.0. In my ASP.Net 1.1 project I had a Module that exposed public functions that returned Datasets, Datareaders etc from the database.

    I cannot seem to find the Module Template in ASP.Net 2.0, does this not exist anymore?

    Also, should I be using a Module in this form. The only problem with a class is that I would have to instantiate it on every page when I want to connect to the Database.

  2. #2
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [2005] Best practices and Modules question

    You can use a Class in the same way.

    Class.Yourmethod will work withouth instantiating it. As long as Yourmethod is Public.

  3. #3

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    Re: [2005] Best practices and Modules question

    Quote Originally Posted by Besoup
    You can use a Class in the same way.

    Class.Yourmethod will work withouth instantiating it. As long as Yourmethod is Public.
    Do you know if that is considered the best way? I want my database access code in a separate place than the form code behind.

  4. #4
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2005] Best practices and Modules question

    Quote Originally Posted by Besoup
    You can use a Class in the same way.

    Class.Yourmethod will work withouth instantiating it. As long as Yourmethod is Public.
    You mean Static (as in C#) or Shared (as in VB).
    Show Appreciation. Rate Posts.

  5. #5
    Frenzied Member
    Join Date
    Nov 2001
    Location
    Mass USA
    Posts
    1,674

    Re: [2005] Best practices and Modules question

    Quote Originally Posted by maikeru-sama
    Do you know if that is considered the best way? I want my database access code in a separate place than the form code behind.

    Pretty sure it's the best way... It's what I do in my VS 2005 web apps.

    Yeah, I stand corrected on the declaration.. Harsh is right!

  6. #6
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: [2005] Best practices and Modules question

    Quote Originally Posted by maikeru-sama
    Do you know if that is considered the best way? I want my database access code in a separate place than the form code behind.
    Actually it largely depends on the type of application you are working on.

    Search here and google for 3-tier application in .Net. There may exists different tiered and may be non-tiered ways for accomplishing the thing.

    It is generally considered good to separate database layer from the rest of application.

    You may also want to look into different Patterns and Practices at MSDN site.
    Show Appreciation. Rate Posts.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Best practices and Modules question

    I don't know what the Module Template is so you probably should describe it a bit better.

    Yes, it's alright to call a function on every page. Rule of thumb in ASP.NET is to open your connection as late as possible and close it as soon as possible, so that makes it perfectly acceptable to call a database open connection method on every page (or from a method that you call which in turn opens a connection).

  8. #8

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    Re: [2005] Best practices and Modules question

    When I say Module Template, I mean adding a Module to the project.

    After doing some research, I read that you cannot add a Module to a ASP.Net 2.0 project and that Microsoft is probably trying to get rid of them. This was nothing official from Microsoft, but someone's opinion, with regards to Modules going away.

    I think you all are right. I just wanted to make sure that I am doing things the right way or one of the accepted ways when programming in ASP.Net 2.0.

    When I get time, I am going to make a Class that has shared functions that is used to access my data.

    I am interested in Encrypting the connection string inside of Web.Config, so I will probably move on to that in few.

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Best practices and Modules question

    Read:
    http://davidhayden.com/blog/dave/arc...1/17/2572.aspx

    (Encrypting connection strings in web.config)

Posting Permissions

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



Click Here to Expand Forum to Full Width