简体   繁体   中英

IIS 7 Application Pool - Can't connect to WCF Service

Greetings, I have to following problem. I have a WCF Service which runs under IIS7. Application connects to it and WCF Service makes some requests to DB. I have notice in activity monitor in SQL Server 2005 that after there are exactly 102 active connections, the application pool in IIS7 hangs. After this I can't connect to my WCF Service. Then only IIS7 restart helps. For connection I am using ChannelFactory, it's closed after each request. I've also introduced code like this to be sure that Channel is closed:

catch (FaultException)
{
    Factory.Abort();
    return null;
}
catch (CommunicationException)
{
    Factory.Abort();

    return null;
}
catch (TimeoutException)
{
    Factory.Abort();
    return null;
}
catch (Exception ex)
{
    Factory.Abort();
    return null;
}

finally
{
    Factory.Close();
    Factory.Abort();
}

I have also the following behvavior for my service class:

[ServiceBehavior(InstanceContextMode= InstanceContextMode.Single, ConcurrencyMode=ConcurrencyMode.Multiple, AutomaticSessionShutdown=true)]

I have also the following in my service web.config file:

<serviceBehaviors>
<behavior name="Server.Service1Behavior">
      <dataContractSerializer maxItemsInObjectGraph="2147483647"/>

      <serviceThrottling maxConcurrentCalls="2147483647"
        maxConcurrentSessions="2147483647"
        maxConcurrentInstances="2147483647" />

I tried everything. Please help me because user's can't work like this. Why it's happen that after 102 connections to DB application pool hangs? Here is the code that calls on the database

internal SqlConnection CheckIfConnectionOpen()
    {
        if (_Connection.State != ConnectionState.Open)
        {
            _Connection.Open();
        }
        return _Connection;
    }
using (SqlCommand cmd = new SqlCommand(query, _Connection))
    { 
CheckIfConnectionOpen();
//some parameters for sqlcommand here and execute nonQuery or execute reader
}

Can someone please help me with this because I am still looking for a solution

On a long shot the link below explains a situation when the app pool crashes it does not restart. If you can get it to restart that should decrease the severity of the issue.

http://i.nconspicuo.us/2008/06/25/iis7-on-windows-server-2008-503-service-unavailable-error-application-pool-stops-unexpectedly/

You mentioned you have checked the Channel is closed, it might be good to confirm the DB connections are closed too.

Hope this helps!

您可以设置一个Web场(针对同一IIS的多个进程),这将有助于最大程度地减少问题,并减少对单个进程的依赖(如果一个进程死掉并重新启动,则其他进程可以在那里支撑堡垒直到重新启动。)

As an aside, your code above is equivalent to:

catch (Exception ex)
{
    Factory.Abort();
    return null;
}
finally
{
    Factory.Close();
    Factory.Abort();
}

And it's just as bad. You probably want to log the exception somewhere so that you know what happened.

I'd like to see the code that calls on the database. I'd be concerned you might not be cleaning up properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM