SqlBulkCopy cannot access table

前端 未结 10 1054
渐次进展
渐次进展 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条回答
  • 2021-01-07 22:39

    I recently ran into this same error and came across this post while googling for an answer. I was able to solve the problem by giving the user that is executing the bulk copy command insert and select permissions on the destination table. Originally I had only granted insert permission to the user and got the 'Cannot access destination table' error.

    0 讨论(0)
  • 2021-01-07 22:40

    Bulkcopy expects the table to exists in the database. Also you should have access to this database or table.

    0 讨论(0)
  • 2021-01-07 22:47

    Andrij Ferents answer is valid.

    The destination table must exist before calling SQLBulkCopy. It is a common newbie mistake.

    0 讨论(0)
  • 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).

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