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.InnerException.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 ?
Tech_MenAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Deepak ChauhanSQL Server DBACommented:
Seems issue here

  string FilePath = "C:\\CarsDB.bak";

change it to

  string FilePath = "C:\CarsDB.bak";
0
Deepak ChauhanSQL Server DBACommented:
From the reference of microsoft for the same error. Hope this will help.

You can supperes the transaction scop.

using(TransactionScope ts = new TransactionScope(TransactionScopeOption.Suppress)) {
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
0
Tech_MenAuthor Commented:
hi
sorry but your answer doesn't work for me
i figure is up like that :
 ef.Database.ExecuteSqlCommand(TransactionalBehavior.DoNotEnsureTransaction, "EXEC_BACKUP @BACKUPPATH = {0}, @BKPDATABASE = {1}", new object[] { FilePath, "CarsDB" });
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tech_MenAuthor Commented:
i found how to do it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.