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:
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.
Bulkcopy expects the table to exists in the database. Also you should have access to this database or table.
Andrij Ferents answer is valid.
The destination table must exist before calling SQLBulkCopy
. It is a common newbie mistake.
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:
(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).