I have a stored procedure that runs once a week that's initiated by the user through the click of a button on our internal website. I'd like to automatically backup the database before the code in the procedure actually runs.
So I've created a separate stored procedure with the following code:
DECLARE @Path varchar(50)
SET @Path = '\\1.1.1.1\SQLBackup\DBName' + convert(varchar, getdate(), 10) +'.bak'
BACKUP DATABASE [DBName] TO DISK = @Path WITH NOFORMAT, NOINIT, NAME = N'DBname-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10
I then run the above from my other stored procedure by using
EXEC GenerateRenewalBackup
The problem is that the application times out on the database backup before it even runs the code in the second stored procedure.
Am I going about this the right way? The database is only 38MB in size. Would it be better to configure the database as a job? Can you run a job from a stored procedure? Any guidance would be very helpful. Thank you.