This lists all the connected DBs:
Using con As New SqlConnection(strConnectInstance)
con.Open()
Using cmd As New SqlCommand("sp_databases", con)
cmd.CommandType = CommandType.StoredProcedure
Dim read As SqlDataReader = cmd.ExecuteReader()
While read.Read()
Console.WriteLine(DirectCast(read("DATABASE_NAME"), String))
End While
End Using
End Using
If your DB name is in the list, it's attached.