Take the 2-minute tour ×

I need to somehow copy data from one database to another. I guess best will be SqlBulkCopy. Problem is that, my table Product have 5 more tables connected with ID of product. So product is connected with Product_picture (pictureID, productID), for example. Is there any way to copy Product and all other connected tables with ID (or Identity) from one database to another?

share|improve this question

1 Answer 1

Invoke bulk copy multiple times. Nothing of this is automated in the product, so you have to build this on your own.

Look into table valued parameters. They are much more flexible and offer reasonable performance for bulk jobs. It is probably fast enough.

share|improve this answer
Thanks for fast reply. Do You mean like that: pastebin.com/h6gJ1WJv ? It does copy Product table, but then when Im trying to copy Product_picture Im getting error: The locale id '0' of the source column 'ref_product_picture' and the locale id '1045' of the destination column 'comment' do not match. –  user13657 Sep 30 '13 at 14:09
Your code is conceptually good. Google the error message. It is unrelated to this question. –  usr Sep 30 '13 at 14:13
Ok, I find out that I need to use ColumnMapping. But question is that - will SqlBulkCopy work if I got some Products in Source databse? For example, I got 20 products in SDB, 30 in DDB (s/d source/dest). So if I copy from SDB to DDB will it work? –  user13657 Sep 30 '13 at 14:23
Not sure what you are saying - if SDB contains rows they will be copies, of course. What good was SqlBulkCopy if it could not copy rows? Maybe you mean DDB? Yes, existing rows will be preserved. Bulk copy is nothing but a faster mass insert. –  usr Sep 30 '13 at 14:30

Your Answer


