NunoRibeiro
NunoRibeiro

Reputation: 511

Petapoco execute stored procedure without waiting

I'm using PetaPoco on a C# WepApi and I have to execute a Stored Procedure that deletes rows on many tables. The number of rows to delete it's variable (can be a few or too many) so, sometimes, PetaPoco throws an Exception of timeout. Is it possible, with PetaPoco, to "call" the stored procedure and close the connection before the procedure is done. The Stored Procedure doesn't return any value and the WebApi doesn't need to know when it's over...

Upvotes: 1

Views: 2460

Answers (1)

Eduardo Molteni
Eduardo Molteni

Reputation: 39413

What you need it's to fire a background task and return from the WebApi request. The are several options to run a background task and don't forget to change the request timeout using :

HttpContext.Server.ScriptTimeout = TimeSpan.FromMinutes(50).TotalSeconds;

and the PetaPoco command timeout using:

var db = new Database(connectionStringName);
db.OneTimeCommandTimeout = TimeSpan.FromMinutes(50).TotalSeconds;
db.Execute( ... );

Upvotes: 6

Related Questions