Share via


Cannot access destination table (Sqlbulkcopy)

Question

Monday, September 24, 2012 3:15 PM

Hi Everyone,

Actually I am trying to import excel data to Sql Server for that i am using sqlbulkcopy . I implemented code and I checked with debug mode as well . Data is coming from excel and it storing in datareader but   Here i am getting this error -->Cannot access destination table 'Temp',

 bulkCopy.DestinationTableName = "Temp";
 bulkCopy.WriteToServer(dr); I checked table name structure everything is Fine. But I dont know where exactly the problems.Can anyone please help me out of this.Thanks,Anj

 

All replies (4)

Monday, September 24, 2012 3:48 PM âś…Answered

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

Try this article might be helpful

http://www.thisisvisceral.com/2006/06/importing-excel-into-sql/

Mark it as helpful if so!!! thanks, Mithilesh


Monday, September 24, 2012 4:22 PM | 2 votes

If it makes sense, you can however, bulk-copy data to a temporary table by using a value such as tempdb..#table or tempdb.<owner>.#table for the DestinationTableName property.


Tuesday, September 25, 2012 12:52 PM

Thanks Mithilesh


Tuesday, September 25, 2012 1:59 PM

As I said, you CAN bulk-copy to a temp table using the methodology I provided.