2

I use FSharp.Data.SqlClient type providers to access SQL server database. So, I set up the types in F# something as follows:

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

and then I use it something like that:

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

where ResultData is some type, which "knows" how to convert itself into a row of ResultDataTable (ResultDataTableRow). The extension r.addRow t does that.

Everything is great, except that the row that I am inserting might be fairly large (25-30 MB in size) and so, I have a bad feeling that t.Update(conn) might randomly time out especially due to nearly 100% processor load (the computational system core is designed to consume all processing resources, though at low priority). Hovering over t.Update does not show any way to specify a timeout and any timeout at the level of connection is related, well, to a connection, not to the insert transaction ☹.

So, the question is how to specify timeout for an Update transaction.

Thanks a lot!

20190116 update - So far t.Update(conn) above is holding up without timeouts on my machine while inserting 95MB data rows at 100% below normal load of some other stuff running there. I have not yet measured the actual time for such transactions. If I do, then I will update this.

4

1 回答 1

1

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

但是,正如文档所述,您可能几乎没有自定义默认行为的选项。

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

type AddRow = SqlCommandProvider<"path to the parameterized INSERT statement", designTimeConnection> 
..............................
(new AddRow(runTimeConnection, commandTimeOut=timespan)).Execute(...arg=value...) |> ignore
于 2019-01-10T21:36:44.563 回答