Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8318555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:00:52+00:00 2026-06-08T22:00:52+00:00

I have a table in SQL Server 2008 created as follows: EDIT : I

  • 0

I have a table in SQL Server 2008 created as follows:

EDIT: I had been doing some tests setting ANSI_NULLS OFF and ON and i mistakenly pasted the create table statement with ANSI_NULLS OFF, i have tried both ways and i still get the error but wanted to fix this. Hopefully there is no other paste error.

EDIT 2: I forgot to point out that if i query the original table (TblValues) everything works, the error about the ANSI_NULLS option only occurs when using the db view (TblValuesView).

SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
    QUOTED_IDENTIFIER, ANSI_NULLS ON;
GO
CREATE TABLE TblValues
(
    Context nvarchar(8) NOT NULL,
    ParentID uniqueidentifier NOT NULL,
    RowSeq int NOT NULL,
    FieldValues xml NOT NULL,
    FieldProperties xml NOT NULL,
)  ON [PRIMARY]
 TEXTIMAGE_ON [PRIMARY]

I then loaded this table to my data model and am able to query it using LINQ to EF. The XML content in the FieldValues column is intended to be like this:

<FieldValues>  
  <FieldValue fieldName="txtName">
    <DataType>String</DataType>
    <FldValue>field value</FldValue>
  </FieldValue>
 ...
</FieldValues>

Since i need to provide the values in the xml columns in an easier way to read i created a view for this table as follows:

SET NUMERIC_ROUNDABORT OFF;
SET ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT,
    QUOTED_IDENTIFIER, ANSI_NULLS ON;
GO
CREATE VIEW TblValuesView
WITH SCHEMABINDING
AS
    SELECT TblValuesView.Context,
           TblValuesView.ParentID, 
           TblValuesView.RowSeq, 
           FldValue.value('(@fieldName)[1]', 'nvarchar(30)') AS FieldName, 
           FldValue.value('(DataType)[1]', 'nvarchar(13)') AS DataType, 
           FldValue.value('(FldValue)[1]', 'nvarchar(max)') AS FldValue, 
    FROM   TblValues CROSS APPLY FieldValues.nodes('/FieldValues/FieldValue') AS FldValues(FldValue)
GO  

Then i added this view to the data model as well. Now if i query this view from SQL Server Management Studio i get the proper values as:

Context |  ParentID | RowSeq | FieldName | DataType | FldValue
----------------------------------------------------------------
Ctx         <id>       1        txtName     String     Field Value

But if perform the following LINQ query:

var FldValueViewQuery = (from row in CTX.TblValuesView select row);
foreach(TblValuesView tblValue in FldValueViewQuery)
     System.Diagnostics.Trace.WriteLine(tblValue.FieldName);

I then get the following exception:

System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details.
System.Data.SqlClient.SqlException: SELECT failed because the following SET options have incorrect settings: 'ANSI_NULLS'. 
Verify that SET options are correct for use with indexed views and/or indexes on computed columns and/or filtered indexes and/or query notifications and/or XML data type methods and/or spatial index operations.

I can only get this error from SQL Server Mgmt studio if i do this:

SET ANSI_NULLS OFF
select * from TblValuesView

I have searched on whether if EF changes this option at runtime and i have already checked that my database has ANSI_NULLS enabled and defaulted to true. What other thing can i check? there are not many resources out there that deal with this scenario.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T22:00:53+00:00Added an answer on June 8, 2026 at 10:00 pm

    I found the culprit.

    Thanks to a colleague that knew how the connection was set up in our data model i found out that a SET ANSI_NULLS OFF command was being executed right when opening the connection to the database causing all of our commands to run with this setting, like this:

    public class MyConnection : DbConnection
    {
        ...
        public override void Open()
        {
            using (SqlCommand cmd = new SqlCommand("SET ANSI_NULLS OFF", (SqlConnection)this.WrappedConnection))
            {
                cmd.ExecuteNonQuery();
            }
        }
        ...
    }
    

    The reason i was given for this was that there is an issue with EF and ANSI_NULLS on .NET 4. But queries like this seem to be required to use ANSI_NULLS ON.

    So in conclusion: Views that contain Xml types DO WORK in Entity Framework when using nodes()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a table named test2 as follows in SQL Server 2008 R2
I have created a MedicalLabResult table on Sql server 2008 that have a Result
I have created a pivot table in MS Sql Server 2008. How can I
Would it be possible in SQL Server 2008 to have a table created with
Tables have been created in our SQL Server 2008 R2 database on a local server,
I have created a statistics in a table using SQL SERVER 2008 . In
I'm in SQL Server 2008 and I have been working on making some older
I have this table structure on a SQL Server 2008 R2 database: CREATE TABLE
I have a table in SQL Server 2008 Table Name : tbl_device Table Structure:
I use SQL Server 2008 and have a table with 5 char typed columns.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.