SqlBulkCopy cannot access table

前端 未结 10 1120
渐次进展
渐次进展 2021-01-07 22:02

After reading in an excel-sheet (to transferTable), I want to add that data to a new table (destinationTable) using SqlBulkCopy, but I\'m getting the error:

         


        
10条回答
  •  旧时难觅i
    2021-01-07 22:50

    I had the same issue stating

    tablename-object not found or insufficient privileges.

    It worked fine on my account but not on the end users account, where it gave this error. It turned out that if you run bulkcopy with SqlBulkCopyOptions.KeepIdentity as option, the connection user needs the Grant Alter right, if he doesn't, you will get this not very helpful error message.

    options one has:

    • remove Identity from the destination table
    • grant Alter right on destination table for that user
    • not use KeepIdentity

    (this is an extension of Fosna's answer but given the time it took me to identify the root cause I thought it might be worth to make this solution a bit more explicit).

提交回复
热议问题