sql - Backup database from C# -
I have a stored procedure that works fine when using Windows authentication when I have to run it. If I run it as a standard website user, then I guess it was a matter of permission. So I'm trying to add a script that allows me to connect to the database from C # and run the backup using Windows Certification. I get a code error at any idea? Your database backup process Just too long compared to a regular table query. You can set command timeout through the property The default is 30 seconds, you can also set it to 0 so that it will wait indefinitely. However, this is a bit dangerous because it can lock your site / app. You want to set up your backup processes, instead of another location, such as scheduled tasks.
public bool BackUpDataBase () {string connString = _country == country. England? _connectionStringSiteDbEngland: _connectionStringSiteDbScotland; Try ({SqlConnection conn = new SqlConnection (connString)} {conn.Open (); SqlCommand cmd = New SqlCommand ("BackupDB", conn); Cmd.CommandType = CommandType.StoredProcedure; Cmd.Parameters.Add (new SqlParameter ("@Basalocation", _serverBackupLocation)); Cmd.Parameters.Add (new SqlParameter ("BackupType", _backupType)); Cmd.ExecuteNonQuery (); Back true; }} Hold (exception e) {// :( returning unreal;}}
cmd.ExecuteNonQuery (). The same connection string allows me to connect a database to a table query here IsScheduled public bool {string archiveDB = _country == Country.England _englandArchiveDBName: _scotlandArchiveDBName ; (SqlConnection Conn = New SqlConnection (_country == Country: England; _connectionStringSiteDbEngland: _connectionStringSiteDbScotland); {conn.Open (); SqlCommand cmd = New SqlCommand (SQLToCheckSchedule (), conn); cmd.Com MandType = CommandType.Text; int rows = 0; (SqlDataReader RDR = cmd.ExecuteReader ()) {while (rdr.Read ()) {rows ++;}} conn.Close (); Return rows & gt; 0; }}
cmd.Comma NdTimeout = 1000; // it is in seconds cmd.executeNonQuery ();
Comments
Post a Comment