简体   繁体   English

SQL Server 2005链接的服务器查询不返回预期的错误

[英]SQL Server 2005 Linked Server Query Does Not Return Expected Error

I am querying a linked SQL Server and not getting an error that I do get when querying locally. 我正在查询链接的SQL Server,但没有收到在本地查询时遇到的错误。

Something like this: 像这样:

SELECT CAST(ColumnName AS INT) FROM TableName 从TableName中选择CAST(ColumnName AS INT)

and this: 和这个:

SELECT CAST(ColumnName AS INT) FROM ServerName.DatabaseName.Schema.TableName 从ServerName.DatabaseName.Schema.TableName选择CAST(ColumnName AS INT)

The first query when run locally returns an error 'Arithmetic overflow error converting expression to data type int.' 在本地运行时,第一个查询将返回错误“将表达式转换为数据类型int的算术溢出错误”。 because some values are out of range. 因为某些值超出范围。

However, the second query running from a different server, simply returns all the 'valid' rows. 但是,从不同服务器运行的第二个查询仅返回所有“有效”行。

I expect that this is working as designed, but I have googled and cannot find anywhere that explains the difference in behaviour when querying locally versus distributed. 我希望这可以按设计工作,但是我已经在Google上搜索了,找不到在本地查询与分布式查询时解释行为差异的任何地方。 Can anyone point me in the right direction? 谁能指出我正确的方向? I'd also like to know if there is some configuration option that would change this. 我也想知道是否有一些配置选项可以改变这一点。

Thanks in advance. 提前致谢。

Look at the SET ARITHABORT and SET ANSI_WARNINGS options. 查看SET ARITHABORT和SET ANSI_WARNINGS选项。 When both are off, then the overflow error will be suppressed and a NULL will be returned instead. 当两者都关闭时,将抑制溢出错误,并改为返回NULL。 They can be set in (at least) three different places: the connection, the database or the code. 可以在(至少)三个不同的地方设置它们:连接,数据库或代码。 That means you can sometimes get unexpected behaviour because someone set a database option and forgot about it, or someone is using a connection library that sets certain options differently by default. 这意味着您有时可能会发生意外的行为,因为有人设置了数据库选项却忘记了它,或者有人使用的连接库默认情况下将某些选项设置为不同。 More information here: 此处的更多信息:

http://msdn.microsoft.com/en-us/library/ms191203(v=SQL.90).aspx http://msdn.microsoft.com/zh-CN/library/ms191203(v=SQL.90).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM