Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am having a serious problem which I do not know how to solve. I have written a program with VB.net 2002 and MSDE as the database. However after deploying it at customer's place, they reflected to me an error indicating that the ADO.net connection is closed from time to time. It's not consistent. I would like to know that could it be something to do with MSDE limitations, my coding problems or some others? Please do advice. Do I have to open a database connection, do my select statement and close the database connection immediately after that? or can I open the database connection and close only after the user closes the connection? Currently I am doing the latter way. Please help. Thank you.

Thanks for replying. Do you mean, for example, the OLEDB.OledbConnection that I have to close after every transaction to the MSDE database? Please advice. Thanks a lot.

First of all, you shouldn't be using the OLEDB.OledbConnection at all...MSDE will allow you to use the objects in the System.Data.Sql and System.Data.SqlTypes namespaces, which will provide you with much better performance and a better coding interface.
But yes, you have to close the connection after you're done with it. Something like this:
Dim cn as new SqlConnection(strConnectionString)
cn.Open()
//make command object, call a stored procedure, etc.
cn.Close()In cases where you know you'll be making several queries to the database in a row, (ie one query to get a row in a person table, then another query to get all that person's orders in a transaction table)you'll get better performance if you wait until you're completely done to close the connection. But you definitely shouldn't have any connections open while waiting around for the user to do something.
Good luck,
-SN

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |