SQL 批量插入的替代方案
我需要将数据表单 .csv 文件导入到数据库表(MS SQL Server 2005)中。 SQL BULK INSERT 似乎是一个不错的选择,但问题是我的数据库服务器与我的 WEB 服务器不在同一台机器上。 这个问题描述了同样的问题,但我不知道对我的数据库服务器有任何控制权,并且无法共享其上的任何文件夹。
我需要一种以编程方式导入 .csv 的方法(C#),有什么想法吗?
编辑:这是网站的一部分,用户可以在其中使用 .csv 内容填充表格,这将每周发生一次,甚至更频繁。
I need to import the data form .csv file into the database table (MS SQL Server 2005). SQL BULK INSERT seems like a good option, but the problem is that my DB server is not on the same box as my WEB server. This question describes the same issue, however i don't have any control over my DB server, and can't share any folders on it.
I need a way to import my .csv programatically (C#), any ideas?
EDIT: this is a part of a website, where user can populate the table with .csv contents, and this would happen on a weekly basis, if not more often
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您有多种选择:
这些方法中的任何一种都应该可以完成工作。 如果这只是临时工作,那么最好用您最喜欢的语言编写一个一次性应用程序,只是为了获取数据。如果它需要成为一个长期存在的解决方案,您可能需要考虑 SSIS 或 DTS,因为它们是为它们而设计的。这种情况。
You have several options:
Any of these approaches ought to get the job done. If it is just scratch work it might be best to write a throwaway app in your favorite language just to get the data in. If it needs to be a longer-living solution you may want to look into SSIS or DTS as they are made for this type of situation.
尝试一下 Rhino-ETL,它是一个用 C# 编写的开源 ETL 引擎,甚至可以使用 BOO 来执行简单的 ETL 脚本,因此您不需要一直编译它。
代码可以在这里找到:
https://github.com/hibernating-rhinos/rhino-etl
写道:
http://www.ayende.com/blog
小组列表对此有一些讨论,我实际上不久前为 boo 脚本添加了批量插入。
http://groups.google.com/group/rhino-tools-dev
http://groups.google.com/group/ rhino-tools-dev/browse_thread/thread/2ecc765c1872df19/d640cd259ed493f1
如果您下载代码,其中有多个示例,如果您需要更多帮助,还可以查看 google 群组列表。
Try Rhino-ETL, its an open source ETL engine written in C# that can even use BOO for simple ETL scripts so you don't need to compile it all the time.
The code can be found here:
https://github.com/hibernating-rhinos/rhino-etl
The guy who wrote it:
http://www.ayende.com/blog
The group lists have some discussions about it, I actually added bulk insert for boo scripts a while ago.
http://groups.google.com/group/rhino-tools-dev
http://groups.google.com/group/rhino-tools-dev/browse_thread/thread/2ecc765c1872df19/d640cd259ed493f1
If you download the code there are several samples, also check the google groups list if you need more help.
我最终使用了CSV Reader。 我在 @Jon Skeet 的一个答案中看到了对它的引用,无法再次找到它来放置链接
i ended up using CSV Reader. I saw a reference to it in one of the @Jon Skeet's answers, can't find it again to put the link to it
您的数据集有多大? 除非它们非常大,否则您可以使用参数化插入语句。 出于安心或性能原因,您可能希望首先加载到临时表。
How big are your datasets? Unless they are very large you can get away with parameterized insert statements. You may want to load to a staging table first for peace of mind or performance reasons.