简体   繁体   中英

Slow/quirky LocalDB reconnection on a WPF project after subsequent runs

I have made a very simple database setup for a WPF project. A localDB Database1.mdf is the base for a Dataset1.xsd which was created by drag and dropping the Table I need from the Server Explorer of the Database onto the Dataset Designer. I mainly deal with the data with Dataset variables and the Database Adapter without directly opening and closing the actual database connection programmatically, other than using Update() and Fill() functions of the adapter.

It generally works well during execution, and it is 100% reliable to be up for a first run of the program. There is no issue with it during the program's execution. There is no apparent issue with it during closing the program and the adapter's .Connection.State.ToString() reports "Closed" right before closing and during execution.

However, if I do not wait for at least 10 to 20seconds after quickly re-running the software 2-3 times, the reopening of the program may hang and after a few seconds the debugging report is "Login Failed" during the first Fill(). Why is that? Is there a server limit out of my control, or do I have to close connections manually?

Semi-answer to my own question: Stopping the LocalDB server process with system commands on exit (safely, after waiting for transactions) appears to alleviate the problem somewhat.

For instance, find LocalDB instances

> sqllocaldb i
MSSQLLocalDB
ProjectsV12

To stop the relevant one safely (after queries finish)

> sqllocaldb stop MSSQLLocalDB
LocalDB instance "MSSQLLocalDB" stopped.

Do the same in code with the Process class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM