...
Add a Name and configure the schedule options to your requirements. We recommend running the maintenance job daily at 2:00 am to avoid working hours. Once configured click OK.
Info |
---|
Multiple daily schedules can be added at different times based on the number of records to be archived per day. |
...
Select the Notifications page and check the option Write to the Windows Application event log, from the dropdown options select When the job fails.
...
Create a new text document and name it RxDBMaintenance.ps1
Copy the following below content into the new file and replace the following values in the $connectionString line
<SQL-SERVER\INSTANCE> = Your SQL Server instance name e.g. SQLSRV01\SQLEXPRESS
<database_name> = your ResourceXpress database name e.g. rxpress
Code Block | ||
---|---|---|
| ||
# Initial values, replace the {name} with proper values $connectionString = "Data Source=<SQL-SERVER\INSTANCE-NAME>;Initial Catalog=<database_name>;Integrated Security=False; User ID=dbsupport1;Password=D8Supp0rt!;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False" $timeout = 300 # in seconds $tenantId = 1 Write-Output('DB Maintenance - v0.1 started') # Instantiate the connection to the SQL Database $sqlConnection = new-object System.Data.SqlClient.SqlConnection $sqlConnection.ConnectionString = $connectionString # Define the SQL command to run $sqlCommand = new-object System.Data.SqlClient.SqlCommand $sqlCommand.CommandTimeout = $timeout $sqlCommand.Connection = $sqlConnection $sqlCommand.Parameters.AddWithValue("@TenantId",$tenantId) # Opening the SQL connection try{ $sqlConnection.Open() } catch{ Write-Output('An error occurred in opening connection'+ $_.Exception.ToString()) Exit 1 } # Executing the stored procedures $spList = 'ArchiveConnectivityLog','ArchiveBookingSystemConnectivityLog','ArchiveQubiActivityLog','ArchiveBookings','ArchiveResourceMessages','ArchiveEquipmentProblems','DeleteConnectivityLogArchive','DeleteBookingSystemConnectivityLogArchive','DeleteQubiActivityLogArchive','DeleteBookingsArchive','DeleteResourceMessagesArchive','DeleteEquipmentProblemsArchive','DeleteArchiveLog' foreach($sp in $spList){ try{ Write-Output('About to execute the sp ' + $sp) $sqlCommand.CommandText= 'exec [dbo].[' + $sp + '] @TenantId' $result = $sqlCommand.ExecuteNonQuery() Write-Output($sp + ' executed successfully') } catch{ Write-Output('An error occurred in executing the sp ' + $sp + ' ' + $_.Exception.ToString()) } } # Close the SQL connection $sqlConnection.Close() Write-Output('DB Maintenance is completed successfully') |
Save and close the file.
Open Windows Task Scheduler
...
In the Actions pane select Create Task…, configure the General Settings as below
...
Move on to the Triggers tab and configure the desired schedule. We recommend running the maintenance job daily at 2:00 am to avoid working hours. Click OK.
Info |
---|
Multiple daily schedules can be added at different times based on the number of records to be archived per day. |
...
Click New… in the Actions tab and configure the required options.
The Program/script path should point to PowerShell.exe
In the Add arguments field add -File “C:\Program Files (x86)\QED\RxDBMaintenance\RxDBMaintenance.ps1
Click OK.
...
Configure the Settings tab then click OK to save the task.
...
ResourceXpress Database Maintenance for SQL Express Edition has now been configured.
The new job will be listed in the Task Scheduler Library. If the system has been running for some time you have can run the job immediately instead of waiting for the first scheduled run by right-clicking and selecting Run
Note |
---|
We do not recommend running the job during working hours |
...
Logs
The number of records deleted and or archived are recorded in the database in the ArchiveLog table, to view the logs execute the below SQL query against the ResourceXpress database.
Code Block | ||
---|---|---|
| ||
select * from dbo.ArchiveLog |