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. Database Connection

Database Connection

Scheduled Pinned Locked Moved C#
databasemysqlquestion
5 Posts 2 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.
  • A Offline
    A Offline
    anveshvm
    wrote on last edited by
    #1

    I have a manager class which works as a proxy for connecting to mysql database. I have 2 methods in it, ConnectToDatabase and ExecuteQuery. How should I write the class? Should I make it singleton? Else, if I initiate the class each time, won't it take delay to connect to database?? Thanks in advance Anvesh

    N 1 Reply Last reply
    0
    • A anveshvm

      I have a manager class which works as a proxy for connecting to mysql database. I have 2 methods in it, ConnectToDatabase and ExecuteQuery. How should I write the class? Should I make it singleton? Else, if I initiate the class each time, won't it take delay to connect to database?? Thanks in advance Anvesh

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      anveshvm wrote:

      Else, if I initiate the class each time, won't it take delay to connect to database??

      Initialization of your proxy class will not affect the delay to connect to database. And I don't think you need a singleton implementation here.

      Navaneeth How to use google | Ask smart questions

      A 1 Reply Last reply
      0
      • N N a v a n e e t h

        anveshvm wrote:

        Else, if I initiate the class each time, won't it take delay to connect to database??

        Initialization of your proxy class will not affect the delay to connect to database. And I don't think you need a singleton implementation here.

        Navaneeth How to use google | Ask smart questions

        A Offline
        A Offline
        anveshvm
        wrote on last edited by
        #3

        What about the connection object?? Should I keep the object static for the entire program execution scope. Or should I connect to the database, each time, I have to execute a query?

        N 1 Reply Last reply
        0
        • A anveshvm

          What about the connection object?? Should I keep the object static for the entire program execution scope. Or should I connect to the database, each time, I have to execute a query?

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          anveshvm wrote:

          Or should I connect to the database, each time, I have to execute a query?

          Yeah. That's the right approach.

          anveshvm wrote:

          Should I keep the object static for the entire program execution scope.

          You can keep it if the object is very expensive to build each time. But if it is a simple proxy class, keeping instance will not give performance difference.

          Navaneeth How to use google | Ask smart questions

          A 1 Reply Last reply
          0
          • N N a v a n e e t h

            anveshvm wrote:

            Or should I connect to the database, each time, I have to execute a query?

            Yeah. That's the right approach.

            anveshvm wrote:

            Should I keep the object static for the entire program execution scope.

            You can keep it if the object is very expensive to build each time. But if it is a simple proxy class, keeping instance will not give performance difference.

            Navaneeth How to use google | Ask smart questions

            A Offline
            A Offline
            anveshvm
            wrote on last edited by
            #5

            thank you...

            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