I want to close the existing connections to an SQL Server so that I can do a restore on that database. I am using the entity framework. I tried executing
alter database YourDb
set single_user with rollback immediate
but then I get an exception saying that
Connection was not closed
I can not figure out why the connections are not allowed to close?
This image shows the full exception
this is the method,
public void dbQueueryExctr(string queuery)
{
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
using (SqlConnection connectionx = new SqlConnection(CONNECTIONSTRING))
{
connectionx.Open();
//connectionx.Open(); // Removed
cmd.CommandText = queuery;
cmd.CommandType = CommandType.Text;
cmd.Connection = connectionx;
reader = cmd.ExecuteReader();
connectionx.Close();
}
Edit: I removed the first .Open(). Now I have only Open()