-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclsServiceDataAccess.cs
More file actions
41 lines (36 loc) · 1.2 KB
/
clsServiceDataAccess.cs
File metadata and controls
41 lines (36 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Data;
using System.Data.SqlClient;
namespace MyDatabaseBackupService
{
internal class clsServiceDataAccess
{
public static async void BackupDatabase()
{
try
{
using (SqlConnection connection = new SqlConnection(clsGlobal.ConnectionString))
{
await connection.OpenAsync();
using (SqlCommand command = new SqlCommand(clsGlobal.procedureName, connection))
{
command.CommandType = CommandType.StoredProcedure;
// Execute the stored procedure
await command.ExecuteNonQueryAsync();
}
}
// Log success
clsLog.LogServiceEvent("Backup completed successfully.");
}
catch (SqlException sqlex)
{
clsLog.LogServiceEvent("error, SQL exception : " + sqlex.Message);
}
catch (Exception ex)
{
// Log the exception
clsLog.LogServiceEvent("Error during backup: " + ex.Message);
}
}
}
}