none
A connection that was expected to be kept alive was closed by the server RRS feed

  • Question

  • I'm using a WCF web service which accepts some parameter and connects to database to fetch data. The back-end database is SQL Server 2014. the web service works with some input parameters but doesn't work with some others. the parameters that I got the exception, cause the web method access more tables in database. I also verified that the web method credential has permission to access those tables. 

    deeper investigation shows in the case of error, WCF complains about authentication problem but the point is the web method works for some other input parameters.

    Mohammad.



    Friday, January 2, 2015 7:02 PM

Answers

  • I always test my SQL Queries in SQL Server Management Studio (SSMS) before using them in my VS applications.  The error messages are much better in SSMS than VS.  Your database may be corrupted which is causing the error and not your VS application.

    jdweng

    Tuesday, February 3, 2015 7:09 AM

All replies

  • Can you elaborate your problem further? Also what is the exact error that you are getting
    Sunday, January 4, 2015 11:49 AM
  • Hi Nitin,

    thanks for reply.

      

    assume there is a method in WCF service like:

      public object CalculatePrice(string ProductId)

    when I call method using "A234" it works fine but when I call the method using "B456" which is another product id, it fails.
    the only difference is, in the case of "B456" the method reads from some other SQL tables. I made sure the SQL credential has enough rights for working with those tables.

    this is the full stack trace:

    System.Net.WebException occurred
      _HResult=-2146233079
      _message=The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
      HResult=-2146233079
      IsTransient=false
      Message=The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
      Source=System
      StackTrace:
           at System.Net.HttpWebRequest.GetResponse()
      InnerException: 

    Monday, January 5, 2015 6:44 PM
  • Hi M.Sanati,

    >>The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

    Since your WCF Service works with some parameters but doest not work with others. So in my mind it may be caused by the short timeout value or the message size. Please try to increase the timeout value and increase the supported message size as following in both the service and client side to see if it can work:

    <bindings>
        <basicHttpBinding>
            <binding  allowCookies="true"
                     maxReceivedMessageSize="20000000" 
                     maxBufferSize="20000000"
                     maxBufferPoolSize="20000000"
                     openTimeout="00:20:00" 
                     receiveTimeout="00:20:00" 
                     closeTimeout="00:20:00"
                     sendTimeout="00:20:00">
                <readerQuotas maxDepth="32" 
                     maxArrayLength="200000000"
                     maxStringContentLength="200000000"/>
            </binding>
        </basicHttpBinding>
    </bindings>

    Then please also try to enable the WCF tracing to help find the some detailed error information:
    #How to enable the WCF tracing:
    https://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, February 3, 2015 6:57 AM
    Moderator
  • I always test my SQL Queries in SQL Server Management Studio (SSMS) before using them in my VS applications.  The error messages are much better in SSMS than VS.  Your database may be corrupted which is causing the error and not your VS application.

    jdweng

    Tuesday, February 3, 2015 7:09 AM