My code appears to fail to detach the DB

A

AAaron123

I want to free up a database file in App_Data so that I can backup the
entire solution.

I detached the DB ( think) with the following:
Try

Dim connection As New SqlConnection(ConnectionString)

connection.Open()

Dim command As New SqlCommand("sp_detach_db", connection)

command.CommandType = CommandType.StoredProcedure

command.Parameters.Add(New SqlParameter("@dbname", DatabaseName))

command.Parameters.Add(New SqlParameter("@skipchecks", "'false'"))

command.ExecuteNonQuery()

connection.Close()

Catch ex As SqlException

Throw New ApplicationException("Detach database failed: " + ex.ToString())

End Try

Which I debug step through and it does not through the exception.

But when I try to copy the solution I get the message that the file is being
used by another person or program.

I removed the connection string in my program that would enable my program
to open that DB and then ran the program and detached the DB but still got
the error message.

I waited 20 minutes to let the sessions die and still got the message.

I open the SQL Server 2008 Management Studio and see that the DB is still
listed.

Does that mean it is not detached?

If it were detached it would not be listed - correct?

So it appears something is wrong with my detach code (probably).

Can you suggest something I could try?



Thanks
 
S

S. Justin Gengo

Aaron,

You may need to disable the entire app in IIS (Stop the website altogether).
IIS will put hooks into many of the files within a site's folder doing
things like creating temp files, etc. Typically stopping the site /
application pool will let you get to those files.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
A

AAaron123

I think the session ends after 20 minutes (default) of no usage. Right?
If there are no other sessions won't the app end too?

Thanks


"S. Justin Gengo"
 
S

S. Justin Gengo

Sometimes, but sometimes not. I've seen IIS keep hooks in files for days.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top