zoukankan      html  css  js  c++  java
  • Using ARITHABORT with LLBLGen

    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:

    SQL Server Management Studio : Database Options

    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 this thread 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
    
        /// <summary>
        /// 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.
        /// </summary>
        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
    }
  • 相关阅读:
    企业如何才能“勾搭”上服务网格技术?
    行云创新:云原生加速企业释放数据价值
    行云创新:后疫情时代,云原生为酒店数字化转型破局
    行云创新CEO马洪喜荣获“2021杰出质造人物奖”
    SolarMesh发布 v1.6.1版本,再不来体验就......
    什么是云原生?如何建设云原生平台?
    行云创新联合上汽乘用车打造云原生技术平台,加快实现数字化转型
    五分钟搭建你的第一个区块链应用
    mysql 存储过程
    MySQL-binlog日志格式 binlog_format三种模式详解
  • 原文地址:https://www.cnblogs.com/JamesLi2015/p/2976777.html
Copyright © 2011-2022 走看看