0

Im trying to call a stored procedure with entity framework that makes calls to a different server and I'm getting an error.

I searched on google and it says it is probably becuase Im calling a stored procedure on a DatabaseServer A that queries a table on DatabaseServer B and this causes for a circular reference. I wanted to know if there is a fix for this.

I tried googling the error and everywhere it is stated that I have to change the XACT_ABORT to off. But won't this make that only half my stored procedure goes through?

And I have a different code that calls the same stored procedure and there it works without any errors. I think the reason could be that I use dapper in my other project and here I use entity framwork.

The article of the error I found: https://support.microsoft.com/nl-nl/help/306212/how-to-troubleshoot-error-7391-that-occurs-when-you-use-a-linked-serve

    context.Database.ExecuteSqlCommand("EXEC sp_StoredProcedure @param1,@param2",
        new SqlParameter("param1", param1),
        new SqlParameter("param2", param2));

The expect result is that the database updates go throught. This is the error im getting (note that the original error was in german and I had to google translate it):

The OLE DB provider 'SQLNCLI10' for the connection server 'DB008' could not start a nested transaction. A nested transaction was required because the XACT_ABORT option was set to OFF. The OLE DB provider 'SQLNCLI10' for the connection server 'DB008' has the message 'There is already a registration in the transaction.' hand back

4
  • Have you tried setting XACT_ABORT to ON? :)
    – holder
    Commented Aug 21, 2019 at 8:38
  • I dont have those database rights. So I haven't. Commented Aug 21, 2019 at 8:59
  • @PedroLopes, you don't need any database rights to change the session setting, Just change the query text to SET XACT_ABORT ON;EXEC sp_StoredProcedure.
    – Dan Guzman
    Commented Aug 21, 2019 at 10:31
  • I was able to fix the issue by moving call outside of my entity framework transaction. In my code. Commented Aug 22, 2019 at 10:54

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.