5

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.

3
  • 2
    Put the sproc in a try/catch and look at the exception. Commented Aug 30, 2014 at 19:45
  • Thanks @Shoe, try catch helped me what the problem was. I was passing an output variable in my sp Commented Sep 1, 2014 at 10:14
  • If you have solved your problem be sure to answer with the solution and relevant steps you took to achieve it. Commented Sep 4, 2014 at 4:17

2 Answers 2

2

As suggested by @Shoe, i had embeded the call to stored procedure with in a try catch block which caught the exception and showed the exact error.

It turned out to be that i was not passing the exact variable as the output parameter. Changed result to results as the variable defined in stored procedure was results

var outputParameter = new ObjectParameter("result", typeof(string));
Sign up to request clarification or add additional context in comments.

Comments

0

I just had the same error and I managed to fix it!

This error could be a result of other reasons, but the reason for this error was that the SQL server was not configured to accept transport from my debugging station- I had to configure the IP of my computer in the Sql server settings and then it worked perfectly.

Hope it helps.

1 Comment

Anybody else try this solution?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.