I have created a script to back up a specific database in SQL. I have tested it and it works fine when executed in SQL.
I want to be able to execute this script using Access Front-End to enable an end user to run a back-up when they require.
The query seems to be timing out and I've tried multiple different methods in executing the query.
This is my script to execute a backup.
CREATE PROCEDURE [dbo].[ASP_XXBackUp]
(@name VARCHAR(50), -- database name
@RETURNVALUE CHAR(1) = NULL OUTPUT)
AS
BEGIN
DECLARE @path VARCHAR(256) -- path for backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
-- specify database backup directory
SET @path = 'E:\SQL-Backup\ManualBackup\'
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112) +
REPLACE(CONVERT(VARCHAR(8), GETDATE(), 108),':','')
-- specify filename
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
--Execute BackUp Sequence
BACKUP DATABASE @name TO DISK = @fileName
--Check that we managed to create a successful backup
SELECT TOP 1 @RETURNVALUE = dbo.fc_FileExists(@fileName);
-- Check if succeeded to find.
IF @@ROWCOUNT = 1
SELECT @RETURNVALUE
ELSE
SELECT @RETURNVALUE = 0 --we have failed
END
Is there a way for me to be able to execute this in Access Front-End?
Methods I have tried in Access to execute:
METHOD 1 Dim blnReturnValue As Boolean Dim cmd As ADODB.Command
blnReturnValue = False 'Assume failure
Set cmd = New ADODB.Command
With cmd
.ActiveConnection = gcnn
.CommandText = "ASP_XXBackUp"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("@name", adVarChar, adParamInput, 50, gDatabase)
.Parameters.Append .CreateParameter("@RETURNVALUE", adChar, adParamInputOutput, 1)
.Execute
blnReturnValue = .Parameters("@RETURNVALUE")
Set cmd = Nothing
End With
If blnReturnValue = False Then
Me.ChkBackUp = False
MsgBox "ERROR!: Backup Failed!" & vbCrLf & "Please contact your administrator!"
Else
Me.ChkBackUp = True
MsgBox "SUCCESS!: Databased Backed Up!"
End If
METHOD 2
gcnn.Execute "EXEC ASP_XXBackUp '" & gDatabase & "'"
METHOD 3
'Run proc to create journals for Year end
strSQL = "EXEC ASP_XXBackUp '" & gDatabase & "'"
Call ChangeQueryDef("qryPassThrough_SQL2", strSQL)
Call SQLPassThrough(strQDFName:="qryPassThrough_SQL2", strSQL:=strSQL, strConnect:=gODBCConn)
blnReturnValue = DCount("*", "qryPassThrough_SQL2")