Results 1 to 2 of 2

Thread: For my application, should the data connection object be a global variable?

  1. #1

    Thread Starter
    Hyperactive Member capsulecorpjx's Avatar
    Join Date
    May 2005
    Location
    Renton, WA
    Posts
    288

    For my application, should the data connection object be a global variable?

    I'm creating a new class "XMLFile" in my application.
    Should I pass it the ADO Connection object (byref) in the constructor function?

    Or should I create a static class and create a global connection variable?


    -> Here as an instance of the class is created, a connection object is passed to it, and the constructor sets the class-level connection variable (madoConn) with a reference to the connection object.

    Public Class XMLFile
    Public Sub New(ByRef ladoConn As SqlConnection)
    madoConn = ladoConn
    End Sub
    End Class
    "I like to run on treadmills, because at least I know I'm getting nowhere."
    - Me

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: For my application, should the data connection object be a global variable?

    ADO.NET is not ADO. They are two different things. ADO.NET has been designed specifically so that connections should be created and opened only when needed and closed and discarded immediately afterwards. Follow the CodeBank link in my signature and check out my thread on Retrieving & Saving Data for some examples of how to create and use database connection objects.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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