Sqlbulkcopyoptions.firetriggers does not fire trigger in the table

后端 未结 2 383
说谎
说谎 2021-01-28 02:20

I have a table with a trigger newly added to it.

When I try to run a batch file and upload the file using SqlBulkCopy it did not work.

After reading that addin

相关标签:
2条回答
  • 2021-01-28 03:10

    I tried adding Checkconstraints as well but it says the same error.

    using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.CheckConstraints))

    Is there another way to do it?

    0 讨论(0)
  • 2021-01-28 03:16

    SQL Server requires ALTER TABLE permissions to bulk insert data without the FireTriggers and CheckConstraint options, as well as with the KeepIdentity option, to help safeguard against minimally-privileged users from violating data integrity rules enforced by SQL Server. See What permission do I need to use SqlBulkCopy in SQL Server 2008?.

    The FireTriggers and CheckConstraint options of SqlBulkCopy are off by default to maximize performance. It is the application's responsibility to ensure data integrity that would otherwise be enforced by constraints and triggers when these options are off. Foreign key and check constraints become not trusted after data are bulk copied without these options and must be re-validated with ALTER TABLE...CHECK CONSTRAINT` afterwards before SQL Server will trust the constraints again.

    No special permissions other than SELECT/INSERT to use SqlBulkCopy when FireTriggers and CheckConstraint options are on, and the KeepIdentity option is off.

    0 讨论(0)
提交回复
热议问题