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

  • SEARCH
  • Home
  • 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 6227075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:09:04+00:00 2026-05-24T09:09:04+00:00

I have the following configured within my IContainer Initialize routine: x.For<IDbConnection>().Use<SqlConnection>().Ctor<string>().Is(MY_SQL_CONNECTION_STRING); Here’s the constructor

  • 0

I have the following configured within my IContainer Initialize routine:

x.For<IDbConnection>().Use<SqlConnection>().Ctor<string>().Is(MY_SQL_CONNECTION_STRING);

Here’s the constructor for my service:

private readonly IForumRepository _repo;
public ForumService(IForumRepository repo)
{
    _repo = repo;
}

And here’s the constructor for my repository:

private readonly IDbConnection _cn;
public ForumRepository(IDbConnection connection)
{
    _cn = connection;
}

In one of my service routines, I am calling a method to get an object in my repository, then upon returning to the service layer I call a 2nd method in my repository – however, on this second call to the repository, my connection (_cn) no longer has a connection string associated with it (it appears to be wiped upon exiting the using {} block the first time my service called a method in the repository.

Here’s the first method that I call in the repository.

public Tag GetTag(int id)
{
    Tag o;
    const string q = @"select * from tags where id = @pId";

    using (_cn)
    {
        _cn.Open();
        o = _cn.Query<Tag>(q, new { pId = id }).SingleOrDefault();
    } *** AT THIS POINT THE CONN STRING PROPERTY OF _CN IS CLEARED?!

    return o;
}

I ‘d have thought this should work fine seeing as the constructor for my service instantiates a SQL Connection which the first call to the repo utilizes fine, and seeing as subsequent calls to my repo are in the same service scope I’d have thought that repository’s SqlConnection dependency should still retain the original connection string details.

Can someone please shed some light on where I’m going wrong with this?

  • 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-24T09:09:05+00:00Added an answer on May 24, 2026 at 9:09 am

    After the using block is finished, the object being used will be disposed. Does the connection string get removed on disposal? In any case, you likely shouldn’t use the object after is has been disposed.

    Based on the code in your post, I would think you don’t want to use the using block? I think you will want to manually close the connection, though (I think using will do that automatically as part of disposal).

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

Sidebar

Related Questions

I have an NSMutableArray with objects within it and I use the following code
I've got a following problem: I have configured a ant plugin within my pom.xml
We have configured iReport to generate the following graph: The real data points are
Using CentOS5, I have Apache configured with the following directives. Alias /pscript/ /var/www/pscript/ <Directory
In the web.xml of my web app I have configured the server as following:
I have following string String str = replace :) :) with some other string;
I have following foreach-loop: using System.IO; //... if (Directory.Exists(path)) { foreach(string strFile in Directory.GetFiles(path,
I have following table structure: Table: Plant PlantID: Primary Key PlantName: String Table: Party
I have the following makefile for my project, and I'd like to configure it
I have following situation: I have loged user, standard authentication with DB table $authAdapter

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.