Tech_Men
asked on
backup sql db whit entity framework
hi
i have this sp :
USE [CarsDB]
GO
/****** Object: StoredProcedure [dbo].[EXEC_BACKUP] Script Date: 05/05/2015 20:38:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[EXEC_BACKUP]
( @BACKUPPATH VARCHAR(250),
@BKPDATABASE VARCHAR(100))
AS BEGIN
DECLARE @@STRQUERY NVARCHAR(500)
SET @@STRQUERY = 'BACKUP DATABASE ' + @BKPDATABASE + ' TO DISK = '
+ QUOTENAME(@BACKUPPATH, '''');
EXECUTE SP_EXECUTESQL @@STRQUERY
END;
and from c# form i am running this code to execute the sp :
public static void DoMakeGib()
{
try
{
using (EF.CarsDBEntities ef = new EF.CarsDBEntities())
{
string FilePath = "C:\\CarsDB.bak";
ef.EXEC_BACKUP(FilePath, "CarsDB");
}
}
catch(Exception ex)
{
throw new Exception(ex.InnerExceptio n.Message) ;
}
}
i am geting this error msg :
{"Cannot perform a backup or restore operation within a transaction.\r\nBACKUP DATABASE is terminating abnormally."}
whats wrong ?
i have this sp :
USE [CarsDB]
GO
/****** Object: StoredProcedure [dbo].[EXEC_BACKUP] Script Date: 05/05/2015 20:38:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[EXEC_BACKUP]
( @BACKUPPATH VARCHAR(250),
@BKPDATABASE VARCHAR(100))
AS BEGIN
DECLARE @@STRQUERY NVARCHAR(500)
SET @@STRQUERY = 'BACKUP DATABASE ' + @BKPDATABASE + ' TO DISK = '
+ QUOTENAME(@BACKUPPATH, '''');
EXECUTE SP_EXECUTESQL @@STRQUERY
END;
and from c# form i am running this code to execute the sp :
public static void DoMakeGib()
{
try
{
using (EF.CarsDBEntities ef = new EF.CarsDBEntities())
{
string FilePath = "C:\\CarsDB.bak";
ef.EXEC_BACKUP(FilePath, "CarsDB");
}
}
catch(Exception ex)
{
throw new Exception(ex.InnerExceptio
}
}
i am geting this error msg :
{"Cannot perform a backup or restore operation within a transaction.\r\nBACKUP DATABASE is terminating abnormally."}
whats wrong ?
From the reference of microsoft for the same error. Hope this will help.
You can supperes the transaction scop.
using(TransactionScope ts = new TransactionScope(Transacti onScopeOpt ion.Suppre ss)) {
Your code here....
ts.Complete();
}
https://social.technet.microsoft.com/Forums/es-ES/2c279d4d-217f-4cc1-86c4-8ba704a645eb/cannot-perform-a-backup-or-restore-operation-within-a-transaction-error-when-restoring-database-on?forum=sqlnetfx
You can supperes the transaction scop.
using(TransactionScope ts = new TransactionScope(Transacti
Your code here....
ts.Complete();
}
https://social.technet.microsoft.com/Forums/es-ES/2c279d4d-217f-4cc1-86c4-8ba704a645eb/cannot-perform-a-backup-or-restore-operation-within-a-transaction-error-when-restoring-database-on?forum=sqlnetfx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
i found how to do it
string FilePath = "C:\\CarsDB.bak";
change it to
string FilePath = "C:\CarsDB.bak";