Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6251865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:41:35+00:00 2026-05-24T13:41:35+00:00

Given this snippet of code public abstract class Foo { private static SqlConnection _sqlConnection;

  • 0

Given this snippet of code

public abstract class Foo
{
    private static SqlConnection _sqlConnection;

    protected SqlConnection GetOpenConnection()
    {
        if (_sqlConnection == null)
        {
            _sqlConnection = new SqlConnection("connection string");
        }
        return _sqlConnection;
    }

    protected abstract void Execute();
}

public class FooImpl : Foo
{

    protected override void Execute()
    {
        var myConn = GetOpenConnection();
        var dog = myConn.Query<dynamic>("select 'dog' Animal");
        var first = dog.First();

        string animalType = first.Animal;
        // more stuff here
    }
}

How would you wrap the connection in a profiled connection if you don’t have access to the connection creation process? Rewrite the code in the super class and wrap it there? This would involve changing hundreds of classes that inherit from the base. I’d prefer a way to change the base class, with as little changes necessary to the supers.

Thank you,
Stephen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T13:41:36+00:00Added an answer on May 24, 2026 at 1:41 pm

    Well after a bit of trial and error I compromised and added a ref to MvcMiniProfiler in the base library and changed the connection code a bit.

        protected DbConnection GetOpenConnection()
        {
            if (_connection == null)
            {
                _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connection string "].ConnectionString);
                _connection.Open();
            }
            return MvcMiniProfiler.Data.ProfiledDbConnection.Get(_connection, MiniProfiler.Current); 
        }
    
        private static SqlConnection _connection;
    

    This works for both hosting in the MVC project (for profiling purposes, where we don’t have that capability (QA/Prod Databases)) and WPF/Windows Service

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using EF 4.1 code first. Given the following class snippet: public class Doctor
Here is a VB.NET code snippet Public Class OOPDemo Private _strtString as String Public
Given this class class Foo { // Want to find _bar with reflection [SomeAttribute]
Given the following code snippets, is there any appreciable difference? public boolean foo(int input)
this snippet of code is given me headache. Personally, I would like to use
I am trying to convert the code snippet given in this http://www.movable-type.co.uk/scripts/latlong.html into java.
Given this HTML snippet: <div id=box style=overflow:auto; width:200px; height:200px; border:1px solid black;> 1<br>2<br>3<br>4<br>5<br>6<br>7<br>8<br>9<br>10<br> 11<br>12<br>13<br>14<br>15<br>16<br>17<br>18<br>19<br>20<br>
Given this XML, what XPath returns all elements whose prop attribute contains Foo (the
Given this example: <img class=a /> <img /> <img class=a /> <img class=a id=active
Given this: Public Sub timReminder_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If DateTime.Now()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.