Skip to content

SqlMapper global/default CommandTimeout - #284

Merged
mgravell merged 2 commits into
DapperLib:masterfrom
JesseNaranjo:master
Aug 25, 2015
Merged

SqlMapper global/default CommandTimeout#284
mgravell merged 2 commits into
DapperLib:masterfrom
JesseNaranjo:master

Conversation

@ghost

@ghost ghost commented May 12, 2015

Copy link
Copy Markdown

The way this new property works is by looking at the nullable commandTimeout parameter passed to the CommandDefinition class, and if null, use the new CommandTimeout Setting.

Dapper works via Extension Methods, which are static, therefore not allowing instantiated versions to hold different values. I find that this is OK, given that the option to specify the Command Timeout is provided on each call to Execute, ExecuteReader, Query, and QueryMultiple.

An alternative, which I currently use, but do not like the additional layer is as follows:

  • Create a new class which inherits from DbConnection
  • Act as pass-thru on all of the overridable methods, except CreateDbCommand (which is more involved)
  • In CreateDbCommand, hold the return value in a variable, modify the CommandTimeout property as desired, and return it
  • See sample class here: DB Connection Class with default CommandTimeout

Additional discussion on Issue #282.

I hope this initial design helps pave the way for additional settings and features.

…class will hold some "global" settings, which the SqlMapper will use.
…t value when the CommandDefinition commandTimeout property is not set.
mgravell added a commit that referenced this pull request Aug 25, 2015
SqlMapper global/default CommandTimeout
@mgravell
mgravell merged commit 855d3c1 into DapperLib:master Aug 25, 2015
@ghost

ghost commented Aug 25, 2015

Copy link
Copy Markdown
Author

@mgravell Thanks Marc!

@perragradeen

Copy link
Copy Markdown

How is this used?

Link is broken
See sample class here: DB Connection Class with default CommandTimeout

@perragradeen

Copy link
Copy Markdown

Found it ex.
var items = connection.Query(query, param, commandTimeout: queryTimeoutInSeconds, buffered: false);

(from https://stackoverflow.com/questions/15683197/weird-timeout-issues-with-dapper-net/32524428#32524428)

@ghost

ghost commented Dec 3, 2015

Copy link
Copy Markdown
Author

@perragradeen Link above has been updated. The sample class explains how to subclass/inherit the DbConnection class in order to set a global timeout.

This Pull Request has already been merged into Dapper, so if you're using Dapper, you can simply set SqlMapper.Settings.CommandTimeout = 60. Then, all queries and commands executed via Dapper will have a timeout of 60 seconds (or whatever value you specify).

The more granular option, as you demonstrated above, is to specify the timeout on each query or command independently.

@perragradeen

Copy link
Copy Markdown

I cannot find "Settings" in the static Class Dapper.SqlMapper
Functions that exist are for example SetTypeName(...)

@ghost

ghost commented Dec 14, 2015

Copy link
Copy Markdown
Author

@perragradeen This pull requests is targeted for the 1.5.0 release of Dapper. If you use NuGet, you should be able to use the beta package (though betas are usually not recommended for production use): https://www.nuget.org/packages/Dapper.

@mgravell

Copy link
Copy Markdown
Member

I should note that we're dogfooding the beta in production at
stackoverflow. Will review asap.

On Mon, 14 Dec 2015 21:09 Jesse notifications@github.com wrote:

@perragradeen https://github.com/perragradeen This pull requests is
targeted for the 1.5.0 release of Dapper. If you use NuGet, you should be
able to use the beta package (though betas are usually not recommended for
production use): https://www.nuget.org/packages/Dapper.


Reply to this email directly or view it on GitHub
#284 (comment)
.

@NickCraver

Copy link
Copy Markdown
Member

I really want to rename these, with a unit. e.g. CommandTimeoutSeconds It'd be a breaking change on the global, but less impactful on the param names (still breaking if they're specified in code due to optional). Maybe in a 2.0 release...

@ghost

ghost commented Dec 15, 2015

Copy link
Copy Markdown
Author

@NickCraver feel free to change it. I created the original PR, and since it's in beta, I am probably one of the very few using it.

@mgravell

Copy link
Copy Markdown
Member

IMO: if this is only in the beta - we can do this.

On 15 December 2015 at 01:38, Nick Craver notifications@github.com wrote:

I really want to rename these, with a unit. e.g. CommandTimeoutSeconds
It'd be a breaking change on the global, but less impactful on the param
names (still breaking if they're specified in code due to optional). Maybe
in a 2.0 release...


Reply to this email directly or view it on GitHub
#284 (comment)
.

Regards,

Marc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants