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. sql connection best practise?

sql connection best practise?

Scheduled Pinned Locked Moved C#
databasecsharpperformancehelpquestion
4 Posts 3 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.
  • I Offline
    I Offline
    isarfraz
    wrote on last edited by
    #1

    Dear all, I am developing a desktop application in c# with sqlserver2000, presently my application is doing following steps to communicate with database. 1. Open the connection 2. Create a command 3. Define the input parameter 3. ExecuteNonQuery 4. Assign new values to input parameters 5. ExecuteNonQuery 6 Close Connection I need help in this regard, is this best practise regarding desktop applications or not. what about below option? that i build sql connection and put it in some public object in some class and next time use this global connection object. :)infact i would like to imporve my application speed. Thanks and regards Muhammad Sarfraz

    R 1 Reply Last reply
    0
    • I isarfraz

      Dear all, I am developing a desktop application in c# with sqlserver2000, presently my application is doing following steps to communicate with database. 1. Open the connection 2. Create a command 3. Define the input parameter 3. ExecuteNonQuery 4. Assign new values to input parameters 5. ExecuteNonQuery 6 Close Connection I need help in this regard, is this best practise regarding desktop applications or not. what about below option? that i build sql connection and put it in some public object in some class and next time use this global connection object. :)infact i would like to imporve my application speed. Thanks and regards Muhammad Sarfraz

      R Offline
      R Offline
      Rampas Tomas
      wrote on last edited by
      #2

      I prefer the scenario you described. Just because you benefits from framework built-in connection pooling. You don't need global objects, but remeber for each openning connection you MUST provide the same connection string (means equality of content). For more (and better described;P) details see MSDN documentation or online http://msdn.microsoft.com/vstudio/using/understand/data/default.aspx?pull=/library/en-us/dnadonet/html/adonetbest.asp[^] Tomas Rampas ------------------------------ gedas CR s.r.o. System analyst, MCP TGM 840, 293 01 Mlada Boleslav, Czech Republic Telefon/phone +420(326)711411 Telefax/fax +420(326)711420 rampas@gedas.cz http://www.gedas.com/ ------------------------------ To be or not to be is true... George Bool

      I 1 Reply Last reply
      0
      • R Rampas Tomas

        I prefer the scenario you described. Just because you benefits from framework built-in connection pooling. You don't need global objects, but remeber for each openning connection you MUST provide the same connection string (means equality of content). For more (and better described;P) details see MSDN documentation or online http://msdn.microsoft.com/vstudio/using/understand/data/default.aspx?pull=/library/en-us/dnadonet/html/adonetbest.asp[^] Tomas Rampas ------------------------------ gedas CR s.r.o. System analyst, MCP TGM 840, 293 01 Mlada Boleslav, Czech Republic Telefon/phone +420(326)711411 Telefax/fax +420(326)711420 rampas@gedas.cz http://www.gedas.com/ ------------------------------ To be or not to be is true... George Bool

        I Offline
        I Offline
        isarfraz
        wrote on last edited by
        #3

        dear Tomas Rampas thanks for help my first option in which i open and close connection, i feel would be slow because each time i am opening connection for same sort of things. i have heard from some where that open and close connection is best for web applications and where as for desktop applications you can hold connection object at application level. What u say, i am yet confused(:() thanks again for help :rose:. Muhammad Sarfraz

        K 1 Reply Last reply
        0
        • I isarfraz

          dear Tomas Rampas thanks for help my first option in which i open and close connection, i feel would be slow because each time i am opening connection for same sort of things. i have heard from some where that open and close connection is best for web applications and where as for desktop applications you can hold connection object at application level. What u say, i am yet confused(:() thanks again for help :rose:. Muhammad Sarfraz

          K Offline
          K Offline
          Khang Nguyen
          wrote on last edited by
          #4

          Hello Gurus, I use public/shared connection at Form level for my desktop application. Especially, when you frequently create and destroy connections, performance woud be improved dramatically. One note: you have to close an OleDbDataReader before it lets you reusing the same connection. Khang Nguyen :-D

          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