>IIRC ADO.NET maintains a connection pool and your new SqlConnection() will just grab (or release) an existing connection from the pool. I think there's a ClearPool method - check this:
>
https://msdn.microsoft.com/en-us/library/8xx3tyca(v=vs.110).aspxThis seems to work for others but it does not work for me.
Basically, I have added the clear pool line before my restore procedure:
System.Data.SqlClient.SqlConnection.ClearAllPools()
oStatus.Text = lcRestoringDatabase + "..."
loRestore.Devices.AddDevice(cPath + "\" + cDatabase + ".bak", Microsoft.SqlServer.Management.Smo.DeviceType.File)
loRestore.Database = cDatabase
loRestore.Action = Microsoft.SqlServer.Management.Smo.RestoreActionType.Database
loRestore.ReplaceDatabase = True
loRestore.PercentCompleteNotification = 1
AddHandler loRestore.PercentComplete, AddressOf ProgressEventHandler2
loRestore.SqlRestore(loServer)
And, I still cannot get exclusive use of the database.