I am using the Entity Framework 4.1 within an application. One of the requirments is to execute some stored procedures on the database out of which some take q开发者_开发技巧uite some time. Further, those stored procedures do not return any results so I need to only start them and forget about them.
Naturally, .NET will wait for these operations to complete so after some time it throws an exception that the "Timeout period has expired".
I know that I could fix that by setting the CommandTimeout property to a higher value, however I am looking for an alternative solution (If such even exists).
Is it possible to execute stored procedures using the Entity Framework as Fire-and-Forget?
Any help will be appreciated.
Regards
Stored procedures don't support fire and forget execution. You can either use plain ADO.NET and execute query asynchronously on separate connection (with BeginExecuteNonQuery
). EF doesn't support asynchronous execution. Another more complex way which behaves like fire and forget is creating SQL Job with single step execution your stored procedure. Instead of calling your stored procedure you will call sp_start_job
which returns immediately after starting the job and job will execute asynchronously without returning any other result back to your application.
精彩评论