0

How do I configure CommandTimeout (not Connect Timeout) from connection string in SQL Server?

I thought it'd be simple to find but apparently not. Below I added CommandTimeout=60. It doesn't seem to break anything, but I have no idea if it's actually working or not (and I can't find doc on this)

Data Source=someplace.com;Initial Catalog=MyDB;CommandTimeout=60;User Id=someID;Password=secret;
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
user3761555
  • 621
  • 4
  • 16
  • 2
    it's per command. see https://stackoverflow.com/questions/1198951/how-to-set-the-query-timeout-from-sql-connection-string – muratgu May 28 '19 at 18:30
  • muratgu thanks i read that post, but I need to figure out a way (If it exists) from connection string, not SqlCommand – user3761555 May 28 '19 at 18:41
  • 2
    @user3761555 You can see all the available properties at [SqlConnectionStringBuilder Class](https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnectionstringbuilder?view=netframework-4.8). There is no command timeout available. Perhaps if you [edit] your question to explain the problem you are trying to solve we could help. – Andrew Morton May 28 '19 at 18:55
  • 3
    You ***CANNOT*** set the command timeout in the connection string. You need to specify it on the `SqlCommand` object at runtime – marc_s May 28 '19 at 19:01
  • Tip: If you want to make the command timeout configurable then place it in a separate entry in the appSettings section of your config, and make the code read the timeout value from there, instead of hard-coding it into your application – ADyson May 28 '19 at 19:07
  • The reason why I didnt just set SqlCommand.CommandTimeout is: My project depends on another util project shared by many. In that util project, we use Dapper. I dont want change in that base util project at this point. Thus, looking for an easy way out: If i can set it in connection string, that'd be perfect. – user3761555 May 28 '19 at 19:15
  • Thanks yall, for the confirmation. – user3761555 May 28 '19 at 19:17

0 Answers0