F# - FSharp.Data.SqlClient – 如何指定更新超时

F# - FSharp.Data.SqlClient – How to specify timeout for Update

我使用 FSharp.Data.SqlClient 类型的提供商来访问 SQL 服务器数据库。所以,我在 F# 中设置了如下类型:

type ClmDB = SqlProgrammabilityProvider<ClmSqlProviderName, ConfigFile = AppConfigFile>
type ResultDataTable = ClmDB.dbo.Tables.ResultData
type ResultDataTableRow = ResultDataTable.Row

然后我就这样使用它:

let saveResultData (r : ResultData) (conn : SqlConnection) =
    let t = new ResultDataTable()
    let newRow = r.addRow t
    t.Update(conn) |> ignore
    newRow.resultDataId

其中ResultData是某种类型,其中"knows"如何将自己转换成一行ResultDataTableResultDataTableRow)。扩展 r.addRow t 就是这样做的。

一切都很好,除了我插入的行可能相当大(大小为 25-30 MB),所以,我有一种不好的感觉 t.Update(conn) 可能会随机超时,尤其是由于几乎 100% 的处理器负载(计算系统核心旨在消耗所有处理资源,尽管优先级较低)。将鼠标悬停在 t.Update 上不会显示任何指定超时的方式,连接级别的任何超时都与连接相关,而不是与插入事务 ☹ 相关。

因此,问题是如何为 Update 事务指定超时。

非常感谢!

20190116 更新 - 到目前为止 t.Update(conn) 在我的机器上没有超时,同时插入 95MB 数据行 100% 低于某些 [=36] 的正常负载=]其他东西运行在那里。我还没有测量此类交易的实际时间。如果我这样做,那么我会更新这个。

您不能为所提供的 DataTableUpdate 方法指定超时,因为当前的类型提供程序实现没有提供此类功能。

但是,正如 the documentation 指出的那样,您可能没有几个自定义默认行为的选项。

此外,由于您的用例类似于在 table 中插入单行,因此我会在 SqlCommandProvider 的帮助下使用其构造函数的 commandTimeOut 坚持实施用于设置所需超时值的可选参数 timespan,如下面的代码片段所示:

type AddRow = SqlCommandProvider<"path to the parameterized INSERT statement", designTimeConnection> 
..............................
(new AddRow(runTimeConnection, commandTimeOut=timespan)).Execute(...arg=value...) |> ignore