开发者

It is possible to use SqlBulkCopy to insert information into a view over 2 tables?

I am moving to use SqlBulkCopy to deal with large insertions into some databases. This has lead to great performance improvements for one db.

However, another targeted db table is a view composing 2 tables. Applying the single table code leads to "System.Data.SqlClient.SqlException: View or function 'dbo.vwParameter' is not updatable because the modification affects multiple base tables". It is possible to flatten the view into one table without ca开发者_运维知识库using many complications, though undesired because it saves a good bit disk space.

So is it possible to use SqlBulkCopy in this context, and I am just doing something wrong? Or if not, what might be a good work-around that preserves the view for reading?


It turned out that SqlBulkCopy ignored my instead of triggers by default. All I had to do was pass SqlBulkCopyOptions.FireTriggers to the SqlBulkCopy constructor.


Have you reviewed the documentation about updating data in views? There are two possible solutions described there, and the first one is probably the one you want.


You can use view with SqlBulkCopy.
But I believe your problem is that the view that you have is not updatable.
There are certain requirements that view has to meet to be updatable.
You can find more info here http://msdn.microsoft.com/en-us/library/ms187956.aspx
Look for 'Updatable Views' section.

I would suggest you to populate each of those two tables directly, one at a time, if possible?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜