問題
ConnectionTimeout 是在 ConnectionString 之中設定,
而 CommandTimeout 是設定 Command 物件的 CommandTimeout 屬性。
CommandTimeout 可以在 ConnectionString 之中設定嗎?
解法
如果 Microsoft SQLServer ,並使用SqlClient,是可以的哦~
在SqlConnection.ConnectionString Property中有Command Timeout
屬性可以設定。預設Command Timeout
是30 秒。
所以連線字串設定如下,Data Source=(local);Integrated Security=true;Initial Catalog=Chinook;Command Timeout=300
這樣就不用在Command物件去設定它的CommandTimeout
,只要針對個別的需要不同CommandTimeout
特別設定就可以了。
參考資源
SqlConnection.ConnectionString Property
Setting the command timeout with the latest .NET SqlClient