SQL Server 2008 R2 Express Edition에서 데이터베이스를 삭제할 수있는 C#의 솔루션을 개발 중입니다. 내가 WWW를 검색하고 다음과 같은 솔루션을 발견 : 나는 또한 SQL 서버에서 스크립트를 만들려고 Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)데이터베이스 삭제 SQL Server 2008 R2 Express Edition - 예외
을 :
여기EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'apm4reform'
GO
USE [master]
GO
ALTER DATABASE [apm4reform] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
USE [master]
GO
/****** Object: Database [apm4reform] Script Date: 10/10/2013 00:58:06 ******/
DROP DATABASE [apm4reform]
GO
내 코드 내가 사용 :
불행하게도private static bool DropDatabase(SqlConnection tmpConn, string connectionString, string databaseName)
{
string sqlDropDBQuery;
bool result = false;
try
{
tmpConn.ConnectionString = connectionString;
tmpConn.Open();
SqlCommand thisCommand = new SqlCommand();
thisCommand.Connection = tmpConn;
sqlDropDBQuery = string.Format("EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'{0}'\n GO\n USE [master]\n GO\n ALTER DATABASE [{0}] SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO\n USE [master]\n GO\n DROP DATABASE [{0}]\n GO\n", databaseName);
thisCommand.CommandText = sqlDropDBQuery;
thisCommand.ExecuteNonQuery();
result = true;
}
catch (Exception ex)
{
result = false;
}
finally
{
tmpConn.Close();
}
return result;
}
, 항상 예외가 발생합니다.
'GO'근처의 구문이 잘못되었습니다. 'GO'근처의 구문이 잘못되었습니다. 'GO'근처에서 구문이 잘못되었습니다.
도망 치지 않고 시도했습니다. \ n!
제안 사항?
감사합니다, 접근 금지
마지막으로 이동 –
나는 모든 GO를 제거하고 ';' 대신! 덕분에 – tro
'@ "축 어적 문자열"을 들어 본 적이 있습니까? –