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 8192341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:09:20+00:00 2026-06-07T04:09:20+00:00

I’m running into this problem currently in my WCF service. The timeout period elapsed

  • 0

I’m running into this problem currently in my WCF service. “The timeout period elapsed prior to obtaining a connection from the pool”

Now I understand the error, my question is, what is the proper way to manage the Sql connection in a WCF service using Ninject.

What I have done is this.
In the binding I have

 Bind<IConnectionFactory>().To<ConnectionFactory>().InScope(c => OperationContext.Current);

And my connection factory looks like this.

public class ConnectionFactory : IConnectionFactory
{
    private string connectionString = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
    private SqlConnection sqlConnection;

    public SqlConnection GetOpenConnection()
    {
        if (sqlConnection == null)
            sqlConnection = new SqlConnection(connectionString);

        if (sqlConnection.State != ConnectionState.Open)
            sqlConnection.Open();

        return sqlConnection;
    }

    public void CloseConnection()
    {
        sqlConnection.Close();
    }

Whenever I need a Sql connection I invoke it with via an IoC container like this.

 SqlConnection connection = IoC.Resolve<IConnectionFactory>().GetOpenConnection();

My assumption was, that whenever I am dealing with the same request, I would get the same connection back from Ninject, and all connection calls within that request life time will get the same connection. Based on the error, I am assuming this is not happening. Is there a better way of doing this ? Or what is a better connection management paradigm for WCF with ninject ? I feel that making the connection factory a singleton would be the wrong way to go, but that’s just my gut feeling.

EDIT: I would like to add that I inject the connection into my repositories like this

private readonly SqlConnection connection;

    public RandomRepository(IConnectionFactory connectionFactory)
    {
        connection = connectionFactory.GetOpenConnection();
    }
  • 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-06-07T04:09:22+00:00Added an answer on June 7, 2026 at 4:09 am

    Hy,
    You can install Ninject.Extensions.WCF this provides you appropriate scoping for WCF services. Then you can inject an SqlConnection directly into your classes without having to use your connection factory. Simply use a method binding with the appropriate scope. For example with call scope:

    Bind<ISqlConnection>().ToMethod(ctx => ctx.Kernel.Get<IConnectionFactory>().GetOpenConnection()).InCallScope();
    

    Ninject will then take care of disposing the connection when your request is out of scope.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want use html5's new tag to play a wav file (currently only supported

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.