报错:
Exception: Message: ErrorCode: -2147204784, InnerException: System.Data.SqlClient.SqlException:
Length of LOB data (115388) to be replicated exceeds configured maximum 65536.
The statement has been terminated
原因:
是该数据库启动了SQL Server复制,而你尝试插入数据到一个配置了复制的文章的发布列text、ntext或p_w_picpath。
解决方法:
为了解决该错误,先给该数据库做个完备,然后运行一下语句:
sp_configure 'max text repl size', 2147483647
Go
RECONFIGURE
GO
注意:该设置立即生效无需重启SQL Server服务。
https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms186225(v=sql.105)?redirectedfrom=MSDN
更多信息:
“max text repl size”选项以字节为单位,指定了text、ntext、varchar(max)、nvarchar(max)、varbinary(max)、xml和p_w_picpath类型数据,可以以单一的INSERT、UPDATE、WRITETEXT或UPDATETEXT语句添加到被复制的列,或者被捕获的列。默认大小为65536。该值为-1表明没有限制,而无论数据类型。该选项适用于事务复制和变更数据捕获。当一个实例既配置了事务复制又配置了变更数据捕获,该值对两个特性都适用。该选项不适用于快照复制和合并复制
Microsoft SQL Server 2008 R2 (SP2) - 10.50.4000.0 (X64) Standard Edition (64-bit))使用sp_configure更改当前服务器的全局配置设置时,遇到错误提示为“消息 5808,级别 16,状态 1,第 1 行 Ad hoc update to system catalogs is not supported”,一般对应的中文错误提示为:“消息 5808,级别 16,状态 1,第 1 行 不支持对系统目录进行即席更新”。
Code Snippet
EXEC sp_configure'show advanced options', 1;
GO
RECONFIGURE;
GO
Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
消息 5808,级别 16,状态 1,第 1 行
Ad hoc update to system catalogs is not supported.
但是如果我将RECONFIGURE 改为RECONFIGURE WITH OVERRIDE 则OK,不会有上面错误。
Code Snippet
EXEC sp_configure'show advanced options', 1;
GO
RECONFIGURE WITH OVERRIDE;
GO
Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
MSDN关于 RECONFIGURE 和 RECONFIGURE WITH OVERRIDE的解释:
RECONFIGURE
指定如果配置设置不需要服务器停止并重新启动,则更新当前运行的值。RECONFIGURE 还会检查新的配置值中是否有无效值(例如,在 syscharsets 中不存在的排序顺序值)或非建议值。对于那些不需要服务器停止并重新启动的配置选项,其当前运行的值和当前配置的值在指定 RECONFIGURE 之后应当相同。
WITH OVERRIDE
禁用对 recoveryinterval 高级配置选项的配置值检查(以查找无效值或非建议值)。
任何配置选项都可以通过使用 WITH OVERRIDE 选项来重新配置。另外,RECONFIGURE WITH OVERRIDE 使用指定值强制重新配置。例如,可使用大于 maxservermemory 配置选项中指定的值来配置minservermemory 配置选项。但是,这将被认为是错误。因此,指定 RECONFIGURE WITH OVERRIDE 将不禁用配置值检查。
一般造成上面错误的原因是因为allow_updates被设置为1,关于allow updates选项的MSDN解释
allow updates Option
This option is still present in the sp_configure stored procedure, although its functionality is unavailable in SQL Server. The setting has no effect. Starting with SQL Server 2005, direct updates to the system tables are not supported.
Important:
This feature will be removed in a future version of Microsoft SQL Server. Do not use this feature in new development work, and modify applications that currently use this feature as soon as possible.
Changing the allow updates option will cause the RECONFIGURE statement to fail. Changes to the allow updates option should be removed from all scripts.
此选项仍然存在于 sp_configure 存储过程中,但是其功能在 SQL Server 中不可用。其设置不起作用。从 SQL Server 2005 开始,不支持直接更新系统表
更改 allow updates 选项将导致 RECONFIGURE 语句失败。 应当从所有脚本中删除对 allow updates 选项的更改。
我检查了一下数据库关于'allow_updates' 选项的config_value和 run_value,果然发现其值为1,使用sp_configure将其置为0后,使用RECONFIGURE时,不会出现上面错误
EXEC sp_configure 'allow_updates'
name minimum maximum config_value run_value
------------- ----------- ----------- ------------ -----------
allow updates 0 1 1 1
EXEC sp_configure 'allow_updates',0;
GO
RECONFIGURE WITH OVERRIDE;
GO
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
Configuration option 'show advanced options' changed from 0 to 1. Run the RECONFIGURE statement to install.
EXEC sp_configure'show advanced options', 1;
GO
RECONFIGURE;
GO
配置选项 'show advanced options' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装