博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Using ARITHABORT with LLBLGen
阅读量:4347 次
发布时间:2019-06-07

本文共 2934 字,大约阅读时间需要 9 分钟。

I have recently been developing an application that uses LLBLGen with a vendor product SQL Server database. When attempting to add an entity, I was presented with the following exception:

SD.LLBLGen.Pro.ORMSupportClasses.ORMQueryExecutionException was unhandled

  Message="An exception was caught during the execution of an action query: INSERT failed because the following SET options have incorrect settings: ‘ARITHABORT’. Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or query notifications and/or xml data type methods.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception."
  Source="SD.LLBLGen.Pro.ORMSupportClasses.NET20"

To date I had only used LLBLGen with Oracle databases so this exception had me a little confused to start with. After a little research it became clear the easy option is to turn on this option for the database as a whole, as shown below in the screenshot from SQL Server Management Studio:

However, I did not really want to go changing options in a vendor products database as I do not know what effect this could have on the actual product client code.

LLBLGen provides a method to set this value. If using the adapter method, you can achieve this by calling DataAccessAdapter.SetArithAbortFlag(true); This will then wrap each dynamically generated query with SET ARITHABORT ON; … SET ARITHABORT OFF; When I tried this, it had no effect; I could see that the generated dynamic SQL clearly contained the instructions to set ARITHABORT on and off, but still got the same exception.

Further investigation seemed to suggest that you may need to set or clear this flag in a separate batch to the query in which you need it enabled or disabled, which the SetArithAbortFlag technique does not do. Eventually, I came across on the LLBLGen forum.

Based on that article, I came up with the following implementation of OpenConnection() which has solved the issue for me, hopefully it will for somebody else out there too.

internal class REDataAccessAdapter : DataAccessAdapter{    #region Overrides of DataAccessAdapterBase    ///     /// Opens the active connection object. If the connection is already open, nothing is done.    ///             If no connection object is present, a new one is created. This has been    ///             overridden in order to execute a SET ARITHABORT ON before any dynamic SQL    ///             is executed.    ///     public override void OpenConnection()    {        base.OpenConnection();        var connection = GetActiveConnection();        var command = connection.CreateCommand();        command.CommandText = "SET ARITHABORT ON";        var arithAbortQuery = new ActionQuery(connection, command);        WireTransaction(arithAbortQuery);        arithAbortQuery.Execute();    }    #endregion}

转载于:https://www.cnblogs.com/JamesLi2015/archive/2013/03/23/2976777.html

你可能感兴趣的文章
Do not use ‘new’ for side effects
查看>>
mysql 安装相关
查看>>
【转载】Unity3D研究院之IOS触摸屏手势控制镜头旋转与缩放
查看>>
C#小知识
查看>>
windows平台下IPython的安装
查看>>
[源码分析]AbstractStringBuilder
查看>>
leetcode 637 python3 76ms 二叉树的层平均值
查看>>
数据机构与算法--索引优先队列
查看>>
互联网史上最伟大的12个网络应用和软件
查看>>
yum安装jdk
查看>>
1127 ZigZagging on a Tree (30 分)树的层次遍历
查看>>
关于UITableView Grouped 头部和尾部的空白留于
查看>>
web.py学习遇到的问题
查看>>
Windows下QT4.8.4编译环境的搭建(转载http://blog.csdn.net/bestgonghuibin/article/details/38933141)...
查看>>
各种光照算法
查看>>
201521123042 《java程序设计》 第八周学习总结
查看>>
python3 “POST data should be bytes or an iterable of bytes...”的解决方法
查看>>
静态方法
查看>>
保护HTTP的安全
查看>>
js 选取子节点时去除非IE浏览器的换行符
查看>>