Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Windows form global object

Windows form global object

Scheduled Pinned Locked Moved C#
databasehelpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Krugger404
    wrote on last edited by
    #1

    Hi, I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this? Ps. The connection object instantiated on login should be visible throughtout the entire application.

    C M 2 Replies Last reply
    0
    • K Krugger404

      Hi, I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this? Ps. The connection object instantiated on login should be visible throughtout the entire application.

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      datastruct wrote:

      I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this?

      What you actually want to do is create a DAL (Data Access/Abstraction Layer) class (or classes). The DAL is either going to be a singleton or a static class. Here is a very basic example:

      public static Dal
      {
      private static SqlConnection theConnection;

      public static ConnectionString
      {
          set
          {
              theConnection = new SqlConnection(value)
          }
      }
      
      public static DataSet SomeQuery(int id)
      {
          // Write the code to perform the query here.
      }
      

      }

      -- modified at 6:50 Saturday 4th August, 2007 (Corrected code)


      Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

      C K 2 Replies Last reply
      0
      • C Colin Angus Mackay

        datastruct wrote:

        I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this?

        What you actually want to do is create a DAL (Data Access/Abstraction Layer) class (or classes). The DAL is either going to be a singleton or a static class. Here is a very basic example:

        public static Dal
        {
        private static SqlConnection theConnection;

        public static ConnectionString
        {
            set
            {
                theConnection = new SqlConnection(value)
            }
        }
        
        public static DataSet SomeQuery(int id)
        {
            // Write the code to perform the query here.
        }
        

        }

        -- modified at 6:50 Saturday 4th August, 2007 (Corrected code)


        Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        You forgot to make somequery static :p

        Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

        C 1 Reply Last reply
        0
        • K Krugger404

          Hi, I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this? Ps. The connection object instantiated on login should be visible throughtout the entire application.

          M Offline
          M Offline
          Manoj Kumar Rai
          wrote on last edited by
          #4

          Create one Singleton class. This should have a member of type "OdbcConnection" The connection to the database should be stablished in the constroctor of this class. This class should have a member function to return the object of type "OdbcConnection".

          Manoj Never Gives up

          C 1 Reply Last reply
          0
          • C Christian Graus

            You forgot to make somequery static :p

            Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

            C Offline
            C Offline
            Colin Angus Mackay
            wrote on last edited by
            #5

            Christian Graus wrote:

            You forgot to make somequery static

            :-O Oops!


            Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

            1 Reply Last reply
            0
            • M Manoj Kumar Rai

              Create one Singleton class. This should have a member of type "OdbcConnection" The connection to the database should be stablished in the constroctor of this class. This class should have a member function to return the object of type "OdbcConnection".

              Manoj Never Gives up

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              Manoj Kumar Rai wrote:

              This class should have a member function to return the object of type "OdbcConnection".

              Why an OdbcConnection?


              Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

              1 Reply Last reply
              0
              • C Colin Angus Mackay

                datastruct wrote:

                I am currently building a window application and i want the system to use a single database connection for all its queries. So, i want to created a global connection object on login and use this very same object throughout my application when a database connection is required. Can you please help me on this?

                What you actually want to do is create a DAL (Data Access/Abstraction Layer) class (or classes). The DAL is either going to be a singleton or a static class. Here is a very basic example:

                public static Dal
                {
                private static SqlConnection theConnection;

                public static ConnectionString
                {
                    set
                    {
                        theConnection = new SqlConnection(value)
                    }
                }
                
                public static DataSet SomeQuery(int id)
                {
                    // Write the code to perform the query here.
                }
                

                }

                -- modified at 6:50 Saturday 4th August, 2007 (Corrected code)


                Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

                K Offline
                K Offline
                Krugger404
                wrote on last edited by
                #7

                Thanks pal.It did solve my issue.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups