Why does SQL Server CE not allow this trigger to fire?

半城伤御伤魂 提交于 2019-12-12 03:19:01

问题


We're using a SQL Server CE database. I understand that there are limitations to the types of trigger that work with a SQL Server CE database. For instance, the trigger on a SQL Server CE table cannot call a stored procedure, but it can update / insert into another table.

What we are after is a trigger to send an email notification when there is a modification (insert/update/delete) to a table. We know that if we set the trigger directly on the table to send an email (EXEC msdb.dbo.sp_send_dbmail) that you will get an error when you attempt to push to the table. Clearly SQL Server CE does not support a trigger on a tracked table which fires a stored procedure.

To get around this we set a trigger on the table, to insert a row into another table (_table_changes), which is not tracked as part of CE synchronisation. On this table (_table_changes) we set a trigger to send the email notification, which we hoped would get around the problem with a tracked CE table trigger not being able to fire a stored procedure, and in turn an email.

However, even though the table is not part of push/pull synchronisation, if we enable the email trigger on it synchronisation will not work. Why is this? How can CE even be aware that a table, which is not part of synchronisation, has a trigger on it which fires a stored procedure to send an email?


回答1:


I don't think it matters whether the table is tracked as part of CE synchronisation or not.

Triggers are not supported in SQL Server Compact Edition 4.0

Differences Between SQL Server Compact and SQL Server

EDIT

According to this MSDN article RDA in SQL Server CE allows triggers on a SQL Server table that RDA pulls data from. It also states that for tracked tables SQL Server triggers can be executed when changes are pushed back to SQL Server.

Triggers. SQL Server Compact Edition does not support triggers. However, triggers can reside on the SQL Server table that RDA pulls data from. For tracked tables, the SQL Server triggers can be executed when changes are pushed back to SQL Server. You might have to specify SET NOCOUNT ON in the trigger logic. This indicates not to return the number of rows affected, because a response of "no rows affected" causes an error for the RDA Push method.

I would check that you are using SET NOCOUNT ON within your trigger.

Having said all this, and as mentioned above, the use of triggers in SQL Server CE are not supported.

Maybe a better solution would be to create a queue table of emails that are required to be sent. When this data is pushed from SQL CE back to your SQL Server you could schedule a SQL Agent job to check the queue table and send mail that way.



来源:https://stackoverflow.com/questions/9717689/why-does-sql-server-ce-not-allow-this-trigger-to-fire

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!