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