Home Database Mysql Tutorial Error:7884,Severity:20,State:1

Error:7884,Severity:20,State:1

Jun 07, 2016 pm 04:10 PM
error state background

背景: 程序异常中断TCPProvider, error: 0 - An existing connection was forcibly closed by the remotehost.,手工执行查询没有问题,不过执行时间要几十秒。Trace程序的执行,发现要数十分钟,经了解,原因在于程序使用了SqlDataReader读取数据,并且在

背景:

程序异常中断“TCPProvider, error: 0 - An existing connection was forcibly closed by the remotehost.”,手工执行查询没有问题,不过执行时间要几十秒。Trace程序的执行,发现要数十分钟,经了解,原因在于程序使用了SqlDataReader读取数据,并且在读取的过程中进行了一系列数据处理,导致整个完成过程时间变得很长。由此怀疑是网络不稳定之类的因素导致处理过程中连接中断,协调之后改为DataTable做一次性数据加载,程序调整之后,出现故障的频繁大大降低,但无法完全杜绝。

进一步检查,发现在SQLServer日志中,有如下错误:

Error: 7884, Severity:20, State: 1. (Params:). The error is printed in terse mode because there waserror during formatting. Tracing, ETW, notifications etc are skipped.

这个错误与sys.messages中的标准描述不一样,在网上搜索没有找到合适的解决方案。

排查:

把查询的表专门导到一台服务器做测试,最终发现与一个nvarchar(max)列有关,随后想起在不久前,因为Logreader出问题,把出问题的数据列从ntext改为nvarchar(max),于是专门测试这个修改,最终确定问题是这个修改导致。

(text/ntext列可能会导致logreaderagent出问题,这个遇到多次了,但没有明确的重现故障的方法,所以不讨论这个)

故障重现:

使用下面的T-SQL创建测试表,数据,并修改ntext列为nvarchar(max)

-- ====================================== ================

-- 创建测试表

-- ======================================================

USE tempdb;

GO

IF OBJECT_ID(N'dbo.tb_test', 'U') IS NOT NULL

DROPTABLE dbo.tb_test;

GO

CREATE TABLEdbo.tb_test(

id intIDENTITY PRIMARYKEY,

Code varchar(50),

Datedatetime,

Value ntext

);

GO

INSERT dbo.tb_test

SELECT TOP(10000)

Code =RIGHT(10000000000 +ABS(CHECKSUM(NEWID())) % (1000 * 2 ), 20),

Date= DATEADD(DAY, CHECKSUM(NEWID()) % 100 , GETDATE() ),

Value =CONVERT(char(36), NEWID() )

FROM sys.all_columns A WITH(NOLOCK)

,sys.all_columns B WITH(NOLOCK)

;

GO



-- ======================================================

-- 修改 ntext 字段类型为 nvarchar(max)

-- ======================================================

ALTER TABLEdbo.tb_test ALTERCOLUMN Value nvarchar(max);

GO



编写程序,查询数据,并且在查询完成前更改数据,这里用 PowherShell 做测试

# 连接字符串

$ConnectionString = "Data Source=127.0.0.1;InitialCatalog=tempdb;Integrated Security=SSPI"



# 打开连接

$SqlCnnectionQuery = New-Object System.Data.SqlClient.SqlConnection -ArgumentList $ConnectionString

$SqlCnnectionQuery.Open()



# 查询数据

$SqlCommandQuery = New-Object System.Data.SQLClient.SQLCommand

$SqlCommandQuery.Connection = $SqlCnnectionQuery

$SqlCommandQuery.CommandText = "SELECT * FROM( SELECT value, row_id = ROW_NUMBER()OVER( PARTITION BY Code ORDER BY date DESC) FROM dbo.tb_test WITH(NOLOCK) )DATAWHERE row_id = 1"

$SqlReader = $SqlCommandQuery.ExecuteReader()



# 修改数据

$SqlCnnectionUpdate = New-Object System.Data.SqlClient.SqlConnection -ArgumentList $ConnectionString

$SqlCnnectionUpdate.Open()

$SqlCommandUpdate = New-Object System.Data.SQLClient.SQLCommand

$SqlCommandUpdate.Connection = $SqlCnnectionUpdate

$SqlCommandUpdate.CommandText = "UPDATE top(1000) dbo.tb_test SET Value =CONVERT(char(36), NEWID() ) WHERE id IN( SELECT TOP 1000 id FROM dbo.tb_testORDER BY id DESC )"

$UpdateRows = $SqlCommandUpdate.ExecuteNonQuery()

$SqlCnnectionUpdate.Close()

"Update $UpdateRows rows."



#读取查询数据

#读取过程中会出现错误

# (SQL 2008 R2 SP2): TCP Provider, error: 0 - Anexisting connection was forcibly closed by the remote host.

# (SQL 2008 R2 SP3): TCP Provider, error: 0 - The specifiednetwork name is no longer available.

At line:1 char:22

"Read query data...."

$ReadRows=0

While($SqlReader.Read()) {$ReadRows+=1}

"Read $ReadRows rows."



# 关闭连接

$SqlReader.Close()

$SqlCnnectionQuery.Close()
Copy after login

故障处理:

对于修改了数据类型的列,将数据重新更新就可以解决 问题(UPDATE 表 SET 修改的列=修改的列)

这个问题测试了 SQL Server2008 到 2014,都存在问题。其中 SQL Server 2008 R2 SP3中测试,SQL Server日志中的错误信息有所不同,是:

Error: 7886, Severity: 20, State: 2.

A read operation on a large object failedwhile sending data to the client. A common cause for this is if the applicationis running in READ UNCOMMITTED isolation level. This connection will beterminated.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Solution to PHP Fatal error: Call to undefined method PDO::prepare() in Jun 22, 2023 pm 06:40 PM

PHP is a popular web development language that has been used for a long time. The PDO (PHP Data Object) class integrated in PHP is a common way for us to interact with the database during the development of web applications. However, a problem that some PHP developers often encounter is that when using the PDO class to interact with the database, they receive an error like this: PHPFatalerror:CalltoundefinedmethodPDO::prep

Solve the problem of 'error: incomplete type is not allowed' in C++ code Solve the problem of 'error: incomplete type is not allowed' in C++ code Aug 26, 2023 pm 08:54 PM

Solve the "error:incompletetypeisnotallowed" problem in C++ code. During the C++ programming process, you sometimes encounter some compilation errors. One of the common errors is "error:incompletetypeisnotallowed". This error is usually caused by operating on an incomplete type. This article will explain the cause of this error and provide several solutions. firstly, I

What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? What should I do if 'Uncaught (in promise) Error: Request failed with status code 500' occurs when using axios in a Vue application? Jun 24, 2023 pm 05:33 PM

It is very common to use axios in Vue applications. axios is a Promise-based HTTP client that can be used in browsers and Node.js. During the development process, the error message "Uncaught(inpromise)Error: Requestfailedwithstatuscode500" sometimes appears. For developers, this error message may be difficult to understand and solve. This article will explore this

0271: What should I do if the computer cannot be turned on due to real time clock error? 0271: What should I do if the computer cannot be turned on due to real time clock error? Mar 13, 2023 am 11:30 AM

Solution to "0271: real time clock error" that cannot boot: 1. Press F1, and in the interface that appears, move the option bar to the third item "Date/Time"; 2. Manually change the system time to the current one time; 3. Press F10 and select yes in the pop-up dialog box; 4. Re-open the notebook to boot normally.

How to set a picture as the background in OneNote How to set a picture as the background in OneNote May 14, 2023 am 11:16 AM

Onenote is one of the best note-taking tools offered by Microsoft. Combined with Outlook and MSTeams, Onenote can be a powerful combination for increasing productivity at work and in personal creative productivity. We have to take notes in a different format, which may be more than just writing things down. Sometimes we need to copy images from different sources and do some editing in our daily work. Images pasted on Onenote can go a long way if you know how to apply the changes. Have you ever encountered a problem when using Onenote that images pasted on Onenote cannot allow you to work easily? This article will look at using images effectively on Onenote. we can

Solve the 'error: expected initializer before 'datatype'' problem in C++ code Solve the 'error: expected initializer before 'datatype'' problem in C++ code Aug 25, 2023 pm 01:24 PM

Solve the "error:expectedinitializerbefore'datatype'" problem in C++ code. In C++ programming, sometimes we encounter some compilation errors when writing code. One of the common errors is "error:expectedinitializerbefore'datatype'". This error usually occurs in a variable declaration or function definition and may cause the program to fail to compile correctly or

How to solve PHP Warning: fopen(): failed to open stream: No such file or directory How to solve PHP Warning: fopen(): failed to open stream: No such file or directory Aug 19, 2023 am 10:44 AM

How to solve PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory In the process of using PHP development, we often encounter some file operation problems, one of which is "PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory"

Solution to PHP Fatal error: Call to undefined function mysqli_connect() Solution to PHP Fatal error: Call to undefined function mysqli_connect() Jun 23, 2023 am 09:40 AM

When writing web applications using PHP, a MySQL database is often used to store data. PHP provides a way to interact with the MySQL database called MySQLi. However, sometimes when using MySQLi, you will encounter an error message, as shown below: PHPFatalerror:Calltoundefinedfunctionmysqli_connect() This error message means that PHP cannot find my

See all articles