locked
to close or not to close connection in databse RRS feed

  • Question

  • hi

    i work on `Windows-mobile and Windows-ce` using `sqlCE`

    and i dont know what better to do.

    to open connection when the program open

    to run any query's... update...delete database and close the

    connection after the program close  ?

    or, open connection run any query's..update...delete database

    and close the connection Immediately ?

    thanks in advance
    Thursday, February 10, 2011 8:03 PM

Answers

  • Hi E_gold,

     

    You can keep the connection open, try to reuse commands, and use SqlCeResultSet for bulk operations. This approach increase the application performance and data access very fast from the SQL CE Database, however as per my observation you just follow the connection open and close approach in each operation, because if you are suppose to keeping connection open throughout the application lifetime you may get memory leak problem. Opening and closing of SQL CE connection performance is very well and you may hardly notice the overhead of opening & closing a connection. during these operation you can also check garbage collection so that you can have an idea what approach would be better for you.

     

    Hope it helps.

     

     


    - Pavan Pareta [MCTS - Windows Mobile 5.0] If you find my post is helpful for you then mark as a answer and vote it.
    • Marked as answer by Jesse Jiang Thursday, February 17, 2011 8:06 AM
    Thursday, February 10, 2011 8:32 PM
  • SQL CE is in-process database. There are really no benefits to closing connections. If you're using SqlCeResultSet (and you probably should for data bound lists) you have to keep connection open.

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Jesse Jiang Thursday, February 17, 2011 8:06 AM
    Friday, February 11, 2011 2:20 AM

All replies

  • Hi E_gold,

     

    You can keep the connection open, try to reuse commands, and use SqlCeResultSet for bulk operations. This approach increase the application performance and data access very fast from the SQL CE Database, however as per my observation you just follow the connection open and close approach in each operation, because if you are suppose to keeping connection open throughout the application lifetime you may get memory leak problem. Opening and closing of SQL CE connection performance is very well and you may hardly notice the overhead of opening & closing a connection. during these operation you can also check garbage collection so that you can have an idea what approach would be better for you.

     

    Hope it helps.

     

     


    - Pavan Pareta [MCTS - Windows Mobile 5.0] If you find my post is helpful for you then mark as a answer and vote it.
    • Marked as answer by Jesse Jiang Thursday, February 17, 2011 8:06 AM
    Thursday, February 10, 2011 8:32 PM
  • SQL CE is in-process database. There are really no benefits to closing connections. If you're using SqlCeResultSet (and you probably should for data bound lists) you have to keep connection open.

     


    This posting is provided "AS IS" with no warranties, and confers no rights.
    • Marked as answer by Jesse Jiang Thursday, February 17, 2011 8:06 AM
    Friday, February 11, 2011 2:20 AM