System.Data.SqlClient.SqlException ----A transport-level error has occurred when receiving results from the server

prasad k 86 Reputation points
2021-09-20T07:01:43.56+00:00

I am getting below issue while performing bulk copy in c#

System.Data.SqlClient.SqlException (0x80131904): A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.) ---> System.ComponentModel.Win32Exception (0x80004005): The specified network name is no longer available at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)

using (SqlBulkCopy bulkCopy = new SqlBulkCopy(connectionstr, SqlBulkCopyOptions.KeepIdentity))

        {
            bulkCopy.DestinationTableName = Table;
            bulkCopy.BulkCopyTimeout = 0;

            foreach (DataColumn dccolumn in dccolumns)
            {
                bulkCopy.ColumnMappings.Add(dccolumn.ColumnName, dccolumn.ColumnName);
            }

            // Write from the source to the destination.       


            bulkCopy.WriteToServer(dt);

            bulkCopy.Close();
        }
    }

Please advise.

Developer technologies | ASP.NET | Other
SQL Server | Other
Developer technologies | C#
{count} votes

3 answers

Sort by: Most helpful
  1. YufeiShao-msft 7,146 Reputation points
    2021-09-20T08:58:29.703+00:00

    Hi @prasad k ,

    It may not be a statement issue, it could be a network related issue with the service provider, your application is unable to connect the database engine. Check your firewall for any blocked setting and raise it with your service provider.

    You also can check your error log first to see if there are any messages which seem to correlate with this error. Try to use DBCC to check if there is any corruption in the database: https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-checkdb-transact-sql?view=sql-server-ver15

    0 comments No comments

  2. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2021-09-20T21:18:15.93+00:00

    Check the SQL Server log to see if there are error messages that correlates in time with these events.

    If there is not, I'm inclined to agree with Yufei that it is a network issue.

    0 comments No comments

  3. Conor Durdy 0 Reputation points
    2023-09-20T13:59:02.38+00:00

    I've run into this a few times, I work in an environment where my laptop is connecting to several different PC's with the same IP address. Something gets buffered in entityframework or SQL, I'm not sure, but this particular error has always been resolved by restarting both the machine hosting the DB and the machine running the EF commands.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.