fsprojects / Rezoom.SQL

Statically typechecks a common SQL dialect and translates it to various RDBMS backends
MIT License
669 stars 25 forks source link

Increase Command Timeout #40

Closed rkosafo closed 5 years ago

rkosafo commented 5 years ago

Hi, Is there a way to increase the command timeout? I have some 2 stored procedures that take a little over 2 mins each and it appears calling them using the vendor statement fails. What is the right way to increase the command timeout?

rspeele commented 5 years ago

Hey, sorry it took a while to get to this. Been out of town for the holidays.

The simplest thing to do is put the timeout in your SQL Server connection string in app.config, like Connection Timeout=300. But then it will apply to all commands.

The more advanced thing you could do is write a ConnectionProvider, inheriting from the abstract base class defined here. Your ConnectionProvider can set the timeout on SQLCommands based on whatever you like. If you want really flexible behavior, you may have to get sneaky and write your own wrapper DbConnection and DbCommand classes for your ConnectionProvider to use -- but these would just be pass-through wrappers to e.g. SqlConnection and SqlCommand for 99% of their API surface. They would have to be in the same namespace as the underlying ones for some of the hacks in CommandBatch to keep working though, fair warning.

Anyway, having written your own ConnectionProvider, you use the ExecutionConfig to convince RZSQL to use it instead of DefaultConnectionProvider. This would be done like so:

open Rezoom
open Rezoom.Execution

let serviceConfig = ServiceConfig()
serviceConfig.SetConfiguration<ConnectionProvider, MyCustomConnectionProvider>()
let executionConfig =
    {   ExecutionConfig.Default with
            ServiceConfig = serviceConfig :> IServiceConfig
    }

let run (plan : Plan<'a>) : Task<'a> =
    execute executionConfig plan