SqlDependency raises an error in another application

I have a project where I need to track changes to a third party database.

SqlDependency is a good solution, but it throws the following error in a third party application.

INSERT error because the following SET parameters are incorrect settings: "ANSI_NULLS, QUOTED_IDENTIFIER, ANSI_PADDING". Confirm that SET parameters 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.

(The app works fine when my test program below doesn't work)

In which SET options does this apply?

The only operation I performed was ALTER DATABASE TestDb SET ENABLE_BROKER

to enable notifications.

I also did:

CREATE QUEUE ContactChangeMessages;

CREATE SERVICE ContactChangeNotifications
    ON QUEUE ContactChangeMessages
    ([http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification]);    

      

Here is my Linqpad test code that works great if I insert / update / delete records in management studio.

void Main() {
    const string cs = "Data Source=.;Initial Catalog=TestDb;Trusted_Connection=True";

    var are = new AutoResetEvent(false);
    using (var connection = new SqlConnection(cs)) {
        connection.Open();
        SqlDependency.Start(cs);
        using (var cmd = new SqlCommand()) {
        cmd.Connection = connection;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "SELECT orderNo FROM dbo.Orders WHERE ProductNo = '111'";

            var dep = new SqlDependency(cmd, null, 60);
    dep.OnChange += (s,e) => { 
                Console.WriteLine(e.Info);
                are.Set();
            };
            using (var reader = cmd.ExecuteReader()) {
                while (reader.Read()) {
                }
            }
            are.WaitOne();
            SqlDependency.Stop(cs);
        }
    }
}

      

I don’t know and cannot change how the third part application connects to the database. I can run the sql profiler if more information is needed.

+1


source to share


1 answer


This applies specifically to the SET options specified in the error message:

SET parameters have incorrect settings: "ANSI_NULLS, QUOTED_IDENTIFIER, ANSI_PADDING".

The correct settings, along with other restrictions, are described in Creating a notification request :

When the SELECT statement is executed as per the notification request, the connection that sends the request must have parameters for the connection to be established as follows:

ANSI_NULLS ON
ANSI_PADDING ON
ANSI_WARNINGS ON
CONCAT_NULL_YIELDS_NULL ON
QUOTED_IDENTIFIER ON
NUMERIC_ROUNDABORT OFF
ARITHABORT ON

      

Note Note

Setting ANSI_WARNINGS to ON implicitly sets ARITHABORT to ON when the database compatibility level is 90. If the database compatibility level is 80 or earlier, ARITHABORT must be explicitly set to ON.



These settings are affected by:

You need to find which property listed in the error message is inappropriate and why (it might be a database setting). This is most likely the compatibility level 80 set in the database.

Update. Never say that you are saying you can successfully create a request notification, but then the application itself does not work. The application must explicitly set one of these options OFF on this connection (you can check by checking sys.dm_exec_sessions). You should contact the application vendor, it looks like it is explicitly (albeit inadvertently) making his application incompatible with request notifications.

+2


source







All Articles