What permission do I need to use SqlBulkCopy in SQL Server 2008?

后端 未结 4 1815
时光取名叫无心
时光取名叫无心 2020-12-31 01:17

Using .NET\'s SqlBulkCopy, what permission do I need to give to the user in SQL Server 2008?

相关标签:
4条回答
  • 2020-12-31 01:37

    http://msdn.microsoft.com/en-us/library/ms162802.aspx

    A bcp out operation requires SELECT permission on the source table.

    A bcp in operation minimally requires SELECT/INSERT permissions on the target table. In addition, ALTER TABLE permission is required if any of the following is true:

    • Constraints exist and the CHECK_CONSTRAINTS hint is not specified. ms162802.note(en-us,SQL.100).gifNote: Disabling constraints is the default behavior. To enable constraints explicitly, use the -h option with the CHECK_CONSTRAINTS hint.

    • Triggers exist and the FIRE_TRIGGER hint is not specified. ms162802.note(en-us,SQL.100).gifNote: By default, triggers are not fired. To fire triggers explicitly, use the -h option with the FIRE_TRIGGERS hint.

    • You use the -E option to import identity values from a data file.

    Note: Requiring ALTER TABLE permission on the target table was new in SQL Server 2005. This new requirement might cause bcp scripts that do not enforce triggers and constraint checks to fail if the user account lacks ALTER table permissions for the target table.

    0 讨论(0)
  • 2020-12-31 01:41

    Only SELECT/INSERT perms are needed for SqlBulkCopy class to execute successfully. The class issues a INSERT BULK statement against the target SQL Server table. Verified this today on one of our dev servers.

    0 讨论(0)
  • 2020-12-31 01:46

    There is a bulkadmin role that allows BULK INSERT commands. http://msdn.microsoft.com/en-us/library/ms189934(SQL.90).aspx

    0 讨论(0)
  • 2020-12-31 01:57

    To specify these hints from .net:

    var bulkCopy = new SqlBulkCopy(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"],
            SqlBulkCopyOptions.FireTriggers | SqlBulkCopyOptions.CheckConstraints);
    
    0 讨论(0)
提交回复
热议问题