locked
A first chance exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll RRS feed

  • Question

  • I am trying to call a stored procedure using entity framework 6. I get an error on the output message.

    A first chance exception of type 'System.Data.Entity.Core.EntityCommandExecutionException' occurred in EntityFramework.SqlServer.dll

     
    using (var context = new PartnerPortalEntities2())
     {
        var outputParameter = new ObjectParameter("result", typeof(string));
        var spresults = context.assignRoles_CreateAccountAndContacts(user.Id, role, user.AccountId, user.AccountName, user.ContactId, user.FirstName, user.LastName, outputParameter);
        // Control never comes after the above line
        if(spresults.Equals("1"))
        {
           //Do something
        }
        else
        {
            // Do something
        }
    
        }

    When i do a debug, The control goes to line where the stored procedure is called after which we get the above error on the output window and the debugger stops, it never gets into the if statements.

    I have run the stored procedure on SQLserver and it works fine there. Any thoughts what could be the error. I have built the context by generating the code from database.

    Saturday, August 30, 2014 1:21 PM

All replies

  • You need to look up how to use Objectparamter. It seems that it needs a 'context' in that statement.  Also, the output may be a collection, and the 'if’ may not work either.
    Sunday, August 31, 2014 12:07 PM
  • Hello Pradip,

    Since we do know how you code the stored procedure, I am not sure if this is caused by the stored procedure or the dll. To help narrow this issue, please try to follow this example:

    How to: Execute a Query Using a Stored Procedure with In and Out Parameters try with this way to check the output parameter:

    if (name.Value.ToString().Equals("1"))

    To see whether it would work for you.

    If this also throws the same error, I think the dll might not work properly, please try reinstall your Entity Framework from Nuget.

    And these still do not work for you, could you upload your project including the stored procedure to skydrive so that we could download it and test it?

    Best Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, September 1, 2014 1:40 AM