none
EF 4.1 HOW TO SET ANSI_WARNINGS RRS feed

  • Question

  • Anyone know how to SET ANSI_WARNINGS OFF/ON on the database context ? 

    I'm wondering if executing a query is the only way?

    using (...)

    {

    db.Database.SqlQuery<

    DateTime>("SET ANSI_WARNINGS OFF").First();

    }

    We need to do this to prevent the dreaded 8152 exception.

    thanks

    Marty

    Thursday, June 30, 2011 4:11 PM

Answers

  • you can use the user options option of sp_configure to set the default setting for ANSI_WARNINGS for all connections to the server. You can try ExecuteSqlCommand to this. check here. http://msdn.microsoft.com/en-us/library/gg696165(v=VS.103).aspx

    Thanks,

    Esters,


    Just a newbie for everything.
    Friday, July 8, 2011 7:41 AM
  • Thanks, I presume we can call sp_configure to get the defaults and save them, then configure them for inserts to turn them off and back to the original value.  Thanks for the info.  Our project direction is probably going to move in the direction of better unit testing to try to catch string truncation errors but this looks like it might be a work-around if we get desperate.

    thanks again

    Marty

    Tuesday, July 12, 2011 3:32 AM

All replies

  • Please ignore the <DateTime> - that was from another query...
    Thursday, June 30, 2011 4:12 PM
  • Hi,

    What about calling

    this.Database.ExecuteSqlCommand("SET ANSI_WARNINGS OFF");
    

    in your context constructor?

    Then this command will be executed whenever you're creating a context on the database connection for the context.

     


    --Rune
    Thursday, June 30, 2011 6:11 PM
  • Hi, thanks for your reply.  I think we found that sp_reset_connection will actually reset the SET options right before (during) the call to .SaveChanges(), so there's really no way of performing SET operations as far as we can tell and without messing with pooled connections off or any other hack.  Disappointed we can't get an event to inject pre and post commands during calls to sp_executeSQL().

    thanks anyway

    Marty

    Thursday, July 7, 2011 8:24 PM
  • you can use the user options option of sp_configure to set the default setting for ANSI_WARNINGS for all connections to the server. You can try ExecuteSqlCommand to this. check here. http://msdn.microsoft.com/en-us/library/gg696165(v=VS.103).aspx

    Thanks,

    Esters,


    Just a newbie for everything.
    Friday, July 8, 2011 7:41 AM
  • Thanks, I presume we can call sp_configure to get the defaults and save them, then configure them for inserts to turn them off and back to the original value.  Thanks for the info.  Our project direction is probably going to move in the direction of better unit testing to try to catch string truncation errors but this looks like it might be a work-around if we get desperate.

    thanks again

    Marty

    Tuesday, July 12, 2011 3:32 AM