[英]F# - FSharp.Data.SqlClient – How to specify timeout for Update
I use FSharp.Data.SqlClient
type providers to access SQL server database.我使用
FSharp.Data.SqlClient
类型提供程序来访问 SQL 服务器数据库。 So, I set up the types in F# something as follows:所以,我在 F# 中设置类型如下:
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
).其中
ResultData
是某种类型,它“知道”如何将自己转换为一行ResultDataTable
( ResultDataTableRow
)。 The extension r.addRow t
does that.扩展名
r.addRow t
这样做的。
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).一切都很好,除了我插入的行可能相当大(大小为 25-30 MB),因此,我有一种不好的感觉
t.Update(conn)
可能会随机超时,特别是由于接近 100% 的处理器负载(计算系统核心旨在消耗所有处理资源,尽管优先级较低)。 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 ☹.将鼠标悬停在
t.Update
上不会显示任何指定超时的方法,并且连接级别的任何超时都与连接相关,而不是与插入事务☹有关。
So, the question is how to specify timeout for an Update
transaction.所以,问题是如何为
Update
事务指定超时。
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. 20190116更新 - 到目前为止,上面的
t.Update(conn)
在我的机器上没有超时,同时插入 95MB 数据行,低于在那里运行的其他一些东西的正常负载的 100%。 I have not yet measured the actual time for such transactions.我尚未测量此类交易的实际时间。 If I do, then I will update this.
如果我这样做,那么我会更新这个。
You cannot specify timeout for Update
method of a provided DataTable
because the current Type Provider implementation does not provision for such feature.您不能为提供的
DataTable
Update
方法指定超时,因为当前的类型提供程序实现不提供此类功能。
However, as the documentation notes you may have few options for customizing the default behavior.但是,正如文档所指出的,您可能几乎没有自定义默认行为的选项。
In addition, as your use case resembles an insert of a single row into the table I'd stick to an implementation with the help of SqlCommandProvider
using its constructor's commandTimeOut
optional parameter for setting the desired timeout value timespan
, as in a snippet below:此外,由于你的使用情况类似于一个单列的插入到表中我会坚持的帮助下实现
SqlCommandProvider
使用其构造的commandTimeOut
可选参数设置所需的超时值timespan
,如下面的代码段:
type AddRow = SqlCommandProvider<"path to the parameterized INSERT statement", designTimeConnection>
..............................
(new AddRow(runTimeConnection, commandTimeOut=timespan)).Execute(...arg=value...) |> ignore
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.