Dan*_*ler 5 database connection nunit
答案:我没有清理我的ConnectionPools.
解决的方案是:
建立:
测试:
拆除:
SqlConnection.ClearAllPools();原始问题在首页.
大家好
测试场景是:
建立:
测试:
拆除:
一切都很顺利,直到我进入TearDown阶段.我总是得到以下错误:
无法删除数据库"TEMP_NUnit",因为它当前正在使用中.
这让我感到困惑,因为我正在关闭(在finally语句中显式调用conn.Close)并正确地处理(通过using语句)我的所有DbConnection对象.在TearDown到来之前,"TEMP_NUnit"数据库中不应该有任何运行.
如果我关闭NUnit然后重新打开它,SetUp的第2步总是先行.
我不确定我在这里做错了什么.任何指向正确的方向将不胜感激.
啊,但在删除数据库之前你忘了做这件小事:
SqlConnection.ClearAllPools();
Run Code Online (Sandbox Code Playgroud)
By default the connection pool will maintain a connection to the database, even if you closed it before. Doing SqlConnection.ClearAllPools() will actually force all connections to be closed. You can then connect to master and drop the temp database.
It has caused me quite an amount of grief before :)