Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with MiniProfiler #44

JasonGoemaat opened this issue Jun 10, 2011 · 3 comments

Integration with MiniProfiler #44

JasonGoemaat opened this issue Jun 10, 2011 · 3 comments


Copy link

I'm interested in using stackoverflow's MiniProfiler and got it working by modifying two lines, but I wondered if there was a way to do it without changing PetaPoco.cs.

First when creating a command (CreateCommand method), PetaPoco uses _factory if present, otherwise uses connection.CreateCommand. Is there a reason not to use connection.CreateCommand all the time? This is one of the changes I needed to make to get MiniProfiler to work.

The second change was adding this line to OpenSharedConnection:
_sharedConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(_sharedConnection as DbConnection);

If PetaPoco had a method for modifying connections it wouldn't have to reference the new assembly. This doesn't seem the best way though... One for Command might be nice to to enable things like global CommandTimeout changes because I don't like the default timeout, but that might be a setting I could add to the database object...

Declaration in PetaPoco.Database:
public static Func<IDbConnection, IDbConnection> ModConnection = null;

And in OpenSharedConnection:
if (ModConnection != null)
_sharedConnection = ModConnection(_sharedConnection);

And in Application_Start:
PetaPoco.Database.ModConnection = delegate(IDbConnection cnn)
return MvcMiniProfiler.Data.ProfiledDbConnection.Get(cnn as DbConnection);

Since PetaPoco is a single file it might just be better to modify it specifically for this task... Thoughts?

Copy link

Firstly you can pass a connection into PetaPoco. eg. var db = new Database(new SqlConnection(connstring));
There is also a new Timeout property on the Database object so that you can modify the timeout globally or just once.

Copy link

I've made some changes that should facilitate this.

  1. A new virtual method OnConnectionOpened that can be used to hook in the MvcMiniProfiler wrapper. (For balance I've also added a virtual OnConnectionClosing)
  2. Command creation is now always done via the connection object.

Please let me know if this works.

Copy link

I wrote a MiniProfilerProviderFactory that works and I just have to change the provider name with my connect string, I'll take a look though...

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

No branches or pull requests

3 participants