Exception while inserting records in SQL Server (Error message id : 586) I am getting an exception when doing a batch insert operation using a prepared statement from Java.


  java.sql.BatchUpdateException: The prepared statement handle 5 is not
  valid in this context.  Please verify that current database, user
  default schema, and ANSI_NULLS and QUOTED_IDENTIFIER set options are
  not changed since the handle is prepared.


While analyzing this error message all I could find out was its error message id : 586. I could not gather any more information about this issue.

Can anyone help me with the reason for this exception, what it means and how to resolve it ?

Machine Details :

SQL Server Version - SQL Server 2014

jTDS JAR Version - 1.2.4

PS : This exception only occurs on a particular remote machine. We cant reproduce this issue locally. Any tips on how to reproduce this issue would also be helpful.
It seems that this server has been configured in a different way than the others.

Using SSMS, right click over server instance in some of the servers where the job is running and check that ANSI NULLS and quoted identifier have the same value on this server.



If you prefer to use an script, have a look at:

SET ANSI NULLS
SET QUOTED_IDENTIFIER