March 3, 2003 at 9:40 am
When i drop a database using "DROP DATABASE mydbname" command in query analyzer, the database and the mdf/ldf files get deleted successfully. But when I use the same command using asp.net page, the databse gets deleted but the files do not delete.
I am not able to understand why does SQL behave differently for the same command.
I have used the 'sa' login for both the tasks. I have also tried deleting the database using SQLDMO but there too the database is deleted but the files remain.
To keep my code safe, I have also killed any processes running on the database being dropped.
The code that I have used is as follows:
---------
Try
Dim cmdKillDatabaseProcess As SqlCommand = New SqlCommand("sp_kill_db_process", cn)
cmdKillDatabaseProcess.CommandType = CommandType.StoredProcedure
With cmdKillDatabaseProcess.Parameters
.Add(New SqlParameter("@dbname", SqlDbType.VarChar, 30, ParameterDirection.Input, False, 0, 0, "", DataRowVersion.Current, strDbName))
End With
cmdKillDatabaseProcess.ExecuteNonQuery()
cmdKillDatabaseProcess.Parameters.Clear()
Catch ex As Exception
Response.Write(ex.toString)
End Try
Try
Dim strsqlDropDatabase As String = "drop database " & strDbName
Dim cmdDropDatabase As SqlCommand = New SqlCommand(strsqlDropDatabase, cn)
cmdDropDatabase.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.toString)
End Try
---------
And I get the following error if I try to re-create the database with the same name:
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot create file 'C:\Program Files\Microsoft SQL Server\MSSQL\DATA\paras_db2.mdf' because it already exists. [Microsoft][ODBC SQL Server Driver][SQL Server]CREATE DATABASE failed. Some file names listed could not be created. Check previous errors.
PLEASE HELP
Paras Shah
Evision Technologies
Mumbai, India
Paras Shah
Evision Technologies
Mumbai, India
March 6, 2003 at 8:00 am
This was removed by the editor as SPAM
March 6, 2003 at 9:21 am
Permissions maybe? Havent tested, but maybe even though the account has drop db permission it doesn't have delete permissions on the disk.
Andy
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply