title: A transport-level error has occurred when receiving results from the server error in asp.net c#
body: <p>How to resolve the following Error  </p>
  
  <blockquote>
    <p>"A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)"</p>
  </blockquote>
  
  <p>Here is my web.config code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    --&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="ChartImageHandler" value="storage=file;timeout=20;" /&gt;
    &lt;/appSettings&gt;
    &lt;connectionStrings&gt;
      &lt;add name="paconn" connectionString="Data Source=XYZ-PC;Initial Catalog=crm;MultipleActiveResultSets=True;User ID=sa;Password=xyz@123" providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;system.web&gt;
      &lt;httpRuntime executionTimeout="60000" /&gt;
      &lt;customErrors mode="Off" /&gt;
      &lt;httpHandlers&gt;
        &lt;add path="ChartImg.axd" verb="GET,HEAD,POST" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false" /&gt;
      &lt;/httpHandlers&gt;
      &lt;pages&gt;
        &lt;controls&gt;
          &lt;add tagPrefix="asp" namespace="System.Web.UI.DataVisualization.Charting" assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;
        &lt;/controls&gt;
      &lt;/pages&gt;
      &lt;compilation debug="true" targetFramework="4.0"&gt;
        &lt;assemblies&gt;
          &lt;add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /&gt;
          &lt;add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" /&gt;
          &lt;add assembly="System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
        &lt;/assemblies&gt;
      &lt;/compilation&gt;
      &lt;authentication mode="Forms"&gt;
        &lt;forms loginUrl="~/Account/Login.aspx" timeout="2880" /&gt;
      &lt;/authentication&gt;
      &lt;membership&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
          &lt;add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /&gt;
        &lt;/providers&gt;
      &lt;/membership&gt;
      &lt;profile&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
          &lt;add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" /&gt;
        &lt;/providers&gt;
      &lt;/profile&gt;
      &lt;roleManager enabled="false"&gt;
        &lt;providers&gt;
          &lt;clear /&gt;
          &lt;add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" /&gt;
          &lt;add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /&gt;
        &lt;/providers&gt;
      &lt;/roleManager&gt;
    &lt;/system.web&gt;
    &lt;system.webServer&gt;
      &lt;modules runAllManagedModulesForAllRequests="true" /&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;handlers&gt;
        &lt;remove name="ChartImageHandler" /&gt;
        &lt;add name="ChartImageHandler" preCondition="integratedMode" verb="GET,HEAD,POST" path="ChartImg.axd" type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler, System.Web.DataVisualization, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /&gt;
      &lt;/handlers&gt;
      &lt;directoryBrowse enabled="false" /&gt;
      &lt;defaultDocument&gt;
        &lt;files&gt;
                  &lt;clear /&gt;
                  &lt;add value="Default.asp" /&gt;
                  &lt;add value="Default.htm" /&gt;
                  &lt;add value="index.htm" /&gt;
                  &lt;add value="index.html" /&gt;
                  &lt;add value="iisstart.htm" /&gt;
                  &lt;add value="default.aspx" /&gt;
                  &lt;add value="index.php" /&gt;
        &lt;/files&gt;
      &lt;/defaultDocument&gt;
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>and my C# code that throws the error:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Configuration;
  using System.Data;
  using System.Data.SqlClient;
  
  public partial class autorefresh_create_emi : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["paconn"].ToString());
          con.Open();
  
          SqlCommand com1 = new SqlCommand("select max(f_casenum) from c_detail", con);
          string check_max = com1.ExecuteScalar().ToString();
  
          if (check_max == "0")
          {
          }
          else
          {
              string st_id = "";
              Int64 st = 0;
              string max_id = "";
              Int64 en = 0;
  
              SqlCommand com2 = new SqlCommand("select top 1(f_casenum) from c_emi where f_casenum not in (select top 1 (f_casenum) from c_detail order by f_casenum) order by f_casenum", con);
              st_id = com2.ExecuteScalar().ToString();
              st_id = st_id.Substring(2);
              st = Convert.ToInt64(st_id);
  
              max_id = check_max;
              max_id = max_id.Substring(2);
              en = Convert.ToInt64(max_id);
  
              for (Int64 i = st; i &lt;= en; i++)
              {
                  string f_casenum = "PA" + i;
                  string c_status = "";
                  string f_tenure = "";
  
                  SqlCommand com3 = new SqlCommand("select * from c_detail where f_casenum=@f_casenum", con);
                  com3.Parameters.AddWithValue("@f_casenum", f_casenum);
  
                  SqlDataReader reader3 = com3.ExecuteReader();
                  if (reader3.Read())
                  {
                      f_tenure = reader3["f_tenure"].ToString().Trim();
                      c_status = reader3["c_status"].ToString();
                  }
  
                  if (c_status == "Full Paid")
                  {
                  }
                  else
                  {
                      string row_check = "";
                      SqlCommand com4 = new SqlCommand("select count(f_invoice) from c_emi where f_casenum=@f_casenum", con);
                      com4.Parameters.AddWithValue("@f_casenum", f_casenum);
                      row_check = com4.ExecuteScalar().ToString().Trim();
  
                      if (f_tenure.Equals(row_check))
                      {
                      }
                      else
                      {
                          string st_id_invoice = "";
                          Int64 st_invoice = 0;
                          string max_id_invoice = "";
                          Int64 en_invoice = 0;
  
                          SqlCommand com5 = new SqlCommand("select min(f_invoice) from c_emi where f_casenum=@f_casenum", con);
                          com5.Parameters.AddWithValue("@f_casenum", f_casenum);
                          st_id_invoice = com5.ExecuteScalar().ToString();
  
                          st_id_invoice = st_id_invoice.Substring(3);
                          st_invoice = Convert.ToInt64(st_id_invoice);
  
                          SqlCommand com6 = new SqlCommand("select max(f_invoice) from c_emi where f_casenum=@f_casenum", con);
                          com6.Parameters.AddWithValue("@f_casenum", f_casenum);
                          max_id_invoice = com6.ExecuteScalar().ToString();
  
                          max_id_invoice = max_id_invoice.Substring(3);
                          en_invoice = Convert.ToInt64(max_id_invoice);
  
                          for (Int64 j = st_invoice; j &lt;= en_invoice; j++)
                          {
                              string invoice_date = "";
                              string f_emi_due = "";
                              string f_total_emi = "";
                              string f_emi = "";
                              string f_b_curr = "";
  
                              string f_invoice = "PAI" + j;
                              string f_casenum1 = "";
  
                              SqlCommand com7 = new SqlCommand("select * from c_emi where f_invoice=@f_invoice", con);
                              com7.Parameters.AddWithValue("@f_invoice", f_invoice);
  
                              SqlDataReader reader7 = com7.ExecuteReader();
                              if (reader7.Read())
                              {
                                  f_casenum1 = reader7["f_casenum"].ToString();
                                  f_emi = reader7["f_emi"].ToString();
                                  f_emi_due = reader7["f_emi_due"].ToString();
                                  f_total_emi = reader7["f_total_emi"].ToString();
                                  f_b_curr = reader7["f_b_curr"].ToString();
                                  invoice_date = reader7["invoice_date"].ToString();
                              }
  
                              if (f_casenum == f_casenum1)
                              {
                                  DateTime currr = DateTime.Now;
                                  DateTime INDIAN_ZONE = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(currr, "India Standard Time");
  
                                  DateTime curr = INDIAN_ZONE;
                                  string curr_invoicedate = curr.ToShortDateString();
                                  DateTime check_invoicedate = Convert.ToDateTime(invoice_date);
                                  check_invoicedate = check_invoicedate.AddDays(30);
                                  check_invoicedate = Convert.ToDateTime(check_invoicedate);
                                  string exit_date = check_invoicedate.ToShortDateString();
  
                                  string f_emi_duedate = check_invoicedate.AddDays(10).ToShortDateString();
                                  string invoice_date1 = check_invoicedate.ToShortDateString();
  
                                  SqlCommand com8 = new SqlCommand("select f_casenum from c_emi where f_casenum=@f_casenum and CONVERT(date,invoice_date,101)=@invoice_date", con);
                                  com8.Parameters.AddWithValue("@f_casenum", f_casenum);
                                  com8.Parameters.AddWithValue("@invoice_date", exit_date);
  
                                  string check_exitdate = "";
  
                                  SqlDataReader reader8 = com8.ExecuteReader();
                                  if (reader8.Read())
                                  {
                                      check_exitdate = reader8["f_casenum"].ToString();
                                  }
                                  else
                                  {
                                  }
  
                                  if (check_exitdate != "")
                                  {
                                  }
                                  else
                                  {
                                      if (curr &gt;= check_invoicedate)
                                      {
                                          string value = "0";
                                          string owner = "";
                                          string i_status = "Unlock";
  
                                          SqlCommand com9 = new SqlCommand("select MAX(f_invoice) from c_emi", con);
                                          string maxid1 = com9.ExecuteScalar().ToString();
  
                                          string id1 = maxid1;
                                          Int64 code = 100000000001;
                                          string c = "PAI";
  
                                          if (id1.Substring(0, 1) != "P")
                                          {
                                              id1 = code.ToString();
                                              id1 = c + id1.ToString();
                                          }
                                          else
                                          {
                                              id1 = id1.Substring(3);
                                              Int64 a = Convert.ToInt64(id1);
                                              a = a + 1;
                                              id1 = c + a.ToString();
                                          }
                                          id1 = id1.ToString();
  
                                          SqlCommand com11 = new SqlCommand("insert into c_emi values(@f_casenum,@f_b_amt,@f_emi,@f_emi_duedate,@f_invoice,@invoice_date,@f_overdue_amt,@f_emi_paid,@f_emi_due,@f_total_emi,@f_b_curr,@i_status,@owner,@convi_charges,@paidemi_date)", con);
  
                                          SqlParameter obj1 = new SqlParameter("@f_casenum", DbType.StringFixedLength);
                                          obj1.Value = f_casenum;
                                          com11.Parameters.Add(obj1);
  
                                          SqlParameter obj2 = new SqlParameter("@f_overdue_amt", DbType.StringFixedLength);
                                          obj2.Value = value;
                                          com11.Parameters.Add(obj2);
  
                                          SqlParameter obj3 = new SqlParameter("@f_emi_paid", DbType.StringFixedLength);
                                          obj3.Value = value;
                                          com11.Parameters.Add(obj3);
  
                                          SqlParameter obj4 = new SqlParameter("@f_emi_due", DbType.StringFixedLength);
                                          obj4.Value = value;
                                          com11.Parameters.Add(obj4);
  
                                          SqlParameter obj5 = new SqlParameter("@f_total_emi", DbType.StringFixedLength);
                                          obj5.Value = f_emi;
                                          com11.Parameters.Add(obj5);
  
                                          SqlParameter obj6 = new SqlParameter("@f_emi", DbType.StringFixedLength);
                                          obj6.Value = f_emi;
                                          com11.Parameters.Add(obj6);
  
                                          SqlParameter obj7 = new SqlParameter("@f_emi_duedate", DbType.StringFixedLength);
                                          obj7.Value = f_emi_duedate;
                                          com11.Parameters.Add(obj7);
  
                                          SqlParameter obj8 = new SqlParameter("@f_invoice", DbType.StringFixedLength);
                                          obj8.Value = id1;
                                          com11.Parameters.Add(obj8);
  
                                          SqlParameter obj9 = new SqlParameter("@invoice_date", DbType.StringFixedLength);
                                          obj9.Value = invoice_date1;
                                          com11.Parameters.Add(obj9);
  
                                          SqlParameter obj10 = new SqlParameter("@f_b_amt", DbType.StringFixedLength);
                                          obj10.Value = f_b_curr;
                                          com11.Parameters.Add(obj10);
  
                                          SqlParameter obj11 = new SqlParameter("@f_b_curr", DbType.StringFixedLength);
                                          obj11.Value = f_b_curr;
                                          com11.Parameters.Add(obj11);
  
                                          SqlParameter obj12 = new SqlParameter("@i_status", DbType.StringFixedLength);
                                          obj12.Value = i_status;
                                          com11.Parameters.Add(obj12);
  
                                          SqlParameter obj13 = new SqlParameter("@owner", DbType.StringFixedLength);
                                          obj13.Value = owner;
                                          com11.Parameters.Add(obj13);
  
                                          SqlParameter obj14 = new SqlParameter("@convi_charges", DbType.StringFixedLength);
                                          obj14.Value = value;
                                          com11.Parameters.Add(obj14);
  
                                          SqlParameter obj15 = new SqlParameter("@paidemi_date", DbType.StringFixedLength);
                                          obj15.Value = owner;
                                          com11.Parameters.Add(obj15);
  
                                          com11.ExecuteNonQuery();
                                      }
                                      else
                                      {
                                      }
                                  }
                              }
                              else
                              {
                              }
                          }
                      }
                  }
              }
          }
          con.Close();
      }
  }
  </code></pre>
  
  <p>In line</p>
  
  <pre><code>SqlDataReader reader7 = com7.ExecuteReader();
  </code></pre>
  
  <p>Error Description :</p>
  
  <pre><code>[SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: Session Provider, error: 19 - Physical connection is not usable)]
     System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +388
     System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +815
     System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) +817
     System.Data.SqlClient.TdsParserStateObject.ReadSniSyncOverAsync() +344
     System.Data.SqlClient.TdsParserStateObject.TryReadNetworkPacket() +48
     System.Data.SqlClient.TdsParserStateObject.TryPrepareBuffer() +72
     System.Data.SqlClient.TdsParserStateObject.TryReadByte(Byte&amp; value) +114
     System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean&amp; dataReady) +950
     System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +69
     System.Data.SqlClient.SqlDataReader.get_MetaData() +134
     System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6553981
     System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task&amp; task, Boolean asyncWrite, SqlDataReader ds) +6556619
     System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task&amp; task, Boolean asyncWrite) +586
     System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +104
     System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +288
     System.Data.SqlClient.SqlCommand.ExecuteReader() +302
     autorefresh_create_emi.Page_Load(Object sender, EventArgs e) in e:\phurti_crm\autorefresh_create_emi.aspx.cs:106
     System.Web.UI.Control.LoadRecursive() +71
     System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3178
  </code></pre>
  
  <p>I am using ASP.Net with C# and Database is SQL Server 2012.</p>