C# winforms 응용 프로그램 (.net 2 프레임 워크)이 있습니다. 내 응용 프로그램에서 데이터베이스를 백업해야합니다. SqlCommand를 비동기 적으로 실행하여이 작업을 수행하려고합니다.SqlCommand 백업 데이터베이스
#region backup DB using T-SQL command
string connString = "Data Source=" + ConfigurationManager.AppSettings.Get("localhost_SQLEXPRESS") + ";Initial Catalog=" + db + ";UserID=" + ConfigurationManager.AppSettings.Get("user") + ";Password=" + ConfigurationManager.AppSettings.Get("password");
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connString);
builder.AsynchronousProcessing = true;
using (SqlConnection sqlConnection1 = new SqlConnection(builder.ConnectionString))
{
using (SqlCommand cmd = new SqlCommand("BACKUP DATABASE " + db + " TO DISK=" + location + "\\" + ConfigurationManager.AppSettings.Get("DataBaseBackupsFolderName") + "\\" + db + ".bak'", sqlConnection1))
{
sqlConnection1.Open();
IAsyncResult result = cmd.BeginExecuteNonQuery();
while (!result.IsCompleted)
{
Thread.Sleep(100);
}
}
}
#endregion
당신이 sqlConnection1.Open (에 중단 점을 넣을 수있는 SQL 서버 예외를 받고 있는지 확인하기 위해 정기적 ExecuteNonQuery는과 동기 명령을 시도)와로 (cmd.CommandText의 값을 확인 특히 파일 이름 경로) – Steve
그냥 확인하십시오 ... 백업은 서버에 저장되며 명령을 실행 한 컴퓨터에는 저장되지 않습니다 (두 컴퓨터가 동일한 경우 제외). –
백업은 컴퓨터에 있습니다 ... –