mavera
mavera

Reputation: 3241

Deleting Database in Linq

In normal condition, I can add schemas in the dbml file to empty database with code below.

But now when I run this code, I take the error "Cannot drop database "test" because it is currently in use." How can I do it?

Dim db As New UI_Class.UIData
        If db.DatabaseExists Then
            db.DeleteDatabase()
        End If

    db.CreateDatabase()

Upvotes: 0

Views: 436

Answers (2)

Chris Travers
Chris Travers

Reputation: 26464

Most likely something is connected to the db.

Common causes are:

  1. Some other tool connected
  2. Trying to delete the database you connected to.
  3. Another user connected to the db.

Upvotes: 0

simplyharsh
simplyharsh

Reputation: 36383

It might happen as your SQL Server Management Studio (SSMS) must be holding it.

Upvotes: 1

Related Questions