Friday, March 9, 2012

detach problem

I'm using following connection string in my application in (C# 2.0 windows )

Data Source=.\SQLEXPRESS; Trusted_Connection=yes;AttachDbFilename=|DataDirectory|\myDB.mdf"

My application attaches the file successfully when the first connection is established, but after closing my application the database is remained in the sql server express and it does not detached automatically. According to this article the database shall be detached and I need it in my application because of the security.

http://technet.microsoft.com/en-us/library/ms165716.aspx

Please let me know what shall I do ?

Thanks in advance,

Saeideh

You should always close the conenction to the database as far as you don′t use it anymore.Othwerwise the database will be closed (and detached after a certain period of time). If you have enabled connection pooling it "can take a while" after the pool will be released and the connection will be closed.

http://msdn2.microsoft.com/en-us/library/bb264564.aspx

User instance databases have the Auto Close option set so that if there are no connections to a database for 8-10 minutes, the database shuts down and the file is closed. This happens automatically, but it can take a while, especially if connection pooling is enabled for your connections.

Jens K. Suessmeyer

http://www.sqlserver2005.de

No comments:

Post a Comment