Set CommandTimeOut
Closed this issue · 2 comments
I have a long running query (stored proc actually) that I want to run in a background job using SqlFu. Because the command takes some time it get a System.Data.SqlClient.SqlException: Timeout expired exception after 30 secs, which is the default command timeout.
To solve that, I'm trying to specify a longer CommandTimeout. I thought I found the solution:
SqlFuDao.OnCommand = cmd => cmd.CommandTimeout = 15 * 60;
But it turns out that OnCommand is invoked after the command Executes, so this does not work. Is there any way to accomplish what I want, without falling back to low level SqlConnection.CreateCommand()?
Well, I think you can use something like
db.WithSql(sql,args).Apply(cmd=>{
cmd.CommandTimeout = 15 * 60;
cmd.CommandType=CommandType.StoredProcedure;
} ).Query<Poco>();
But it will work as a simple command not as a Sproc helper.
That does the job, thanks
It also works for migrations: they gave timeouts too that I solved with:
var sql = builder.GetSql();
db.WithSql(sql).Apply(cmd => cmd.CommandTimeout = 2 * 60).Execute();
Btw, there's also a small issue running ExecuteStoredProcedure without params: SqlFu throws an exception.