Using arithabort with llblgen

Source: Internet
Author: User
Tags sql server management sql server management studio

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 configurations 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. ormsuppclasclasses. net20"

To date I had only used llblgen with Oracle databases so this exception had me a little confused to start. 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 cocould 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 cocould 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 authentication SS 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 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.