Z
zydjohn
Guest
Hello:
I created the following stored procedure in [master] database to backup any other databases.
USE [master]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE BackupDB
@name VARCHAR(MAX) = '' -- DB NAME TO CREATE BACKUP
AS
BEGIN
DECLARE @path VARCHAR(256) -- path of backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
SET @path = 'D:\BackupDB\'
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
END
END
GO
I can run this stored procedure by hand from SQL Server Management (Version 18.3.1) in [master] database:
EXEC BackupDB 'MyDBName'
But I want to use C# .NET core program to run this stored procedure, however, all the articles I can find seem rather old.
I need some code examples. I am using Visual Studio 2019 Version 16.3.5 on Windows 10 (Version 1903), targeting .net core 3.0.
Please advice!
Continue reading...
I created the following stored procedure in [master] database to backup any other databases.
USE [master]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create PROCEDURE BackupDB
@name VARCHAR(MAX) = '' -- DB NAME TO CREATE BACKUP
AS
BEGIN
DECLARE @path VARCHAR(256) -- path of backup files
DECLARE @fileName VARCHAR(256) -- filename for backup
DECLARE @fileDate VARCHAR(20) -- used for file name
SET @path = 'D:\BackupDB\'
-- specify filename format
SELECT @fileDate = CONVERT(VARCHAR(20),GETDATE(),112)
BEGIN
SET @fileName = @path + @name + '_' + @fileDate + '.BAK'
BACKUP DATABASE @name TO DISK = @fileName
END
END
GO
I can run this stored procedure by hand from SQL Server Management (Version 18.3.1) in [master] database:
EXEC BackupDB 'MyDBName'
But I want to use C# .NET core program to run this stored procedure, however, all the articles I can find seem rather old.
I need some code examples. I am using Visual Studio 2019 Version 16.3.5 on Windows 10 (Version 1903), targeting .net core 3.0.
Please advice!
Continue reading...