نه چیزی که اینجا میگه اینه که بعضی مواقع مثل alter database ای که مثال زده اینجا، این حالت ÷یش میاد که کانکشن از طرف SQLServer بسته میشه ولی از طرف ADO.NET بسته نمیشه و یه کانکشن InValid ایجاد میشه:
When you issue ALTER DATABASE WITH ROLLBACK IMMEDIATE, SQL Server will
terminate these connections. However, this is not something that ADO .Net
can detect. So it gives you a connection which it thinks is good, but
which isn't.
اما راه حل:
There are a couple of ways to approach this. One is to configure the
connection pool, so that all connections are dropped when you drop the
database. Another is to change the connection string, each time you
drop the database, as different connection strings gives different pools.
I would suggest that the best way, though, is simply to set up an exception
handler, so that you simply trap this error, and then try to reconnect.