franchesco
دوشنبه 05 تیر 1391, 22:08 عصر
با سلام
من یک webpage طراجی کرم تا از دیتابیس بک آپ بگیره.ولی ارور داره !
الن کد منه:
try
{
string _DatabaseName = ddlDatabases.SelectedItem.Text.ToString();
_DatabaseName.Replace(@"\",@"\\");
string _BackupName = _DatabaseName + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + ".bak";
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = _ConnectionString;
sqlConnection.Open();
string sqlQuery = "BACKUP DATABASE " + _DatabaseName + " TO DISK = 'C:\\SQLServerBackups\\" + _BackupName + "' WITH FORMAT, MEDIANAME = 'Z_SQLServerBackups', NAME = '" + _BackupName + "';";
SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection);
sqlCommand.CommandType = CommandType.Text;
int iRows = sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
lblMessage.Text = "The " + _DatabaseName + " database Backup with the name " + _BackupName + " successfully...";
ReadBackupFiles();
}
catch (SqlException sqlException)
{
lblMessage.Text = sqlException.Message.ToString();
}
catch (Exception exception)
{
lblMessage.Text = exception.Message.ToString();
}
}
و اروری که نشان میده اینه !
Incorrect syntax near 'C:'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.
من یک webpage طراجی کرم تا از دیتابیس بک آپ بگیره.ولی ارور داره !
الن کد منه:
try
{
string _DatabaseName = ddlDatabases.SelectedItem.Text.ToString();
_DatabaseName.Replace(@"\",@"\\");
string _BackupName = _DatabaseName + "_" + DateTime.Now.Day.ToString() + "_" + DateTime.Now.Month.ToString() + "_" + DateTime.Now.Year.ToString() + ".bak";
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString = _ConnectionString;
sqlConnection.Open();
string sqlQuery = "BACKUP DATABASE " + _DatabaseName + " TO DISK = 'C:\\SQLServerBackups\\" + _BackupName + "' WITH FORMAT, MEDIANAME = 'Z_SQLServerBackups', NAME = '" + _BackupName + "';";
SqlCommand sqlCommand = new SqlCommand(sqlQuery, sqlConnection);
sqlCommand.CommandType = CommandType.Text;
int iRows = sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
lblMessage.Text = "The " + _DatabaseName + " database Backup with the name " + _BackupName + " successfully...";
ReadBackupFiles();
}
catch (SqlException sqlException)
{
lblMessage.Text = sqlException.Message.ToString();
}
catch (Exception exception)
{
lblMessage.Text = exception.Message.ToString();
}
}
و اروری که نشان میده اینه !
Incorrect syntax near 'C:'. Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.