在.net中加载大量SQL数据并生成CSV文件的最佳方法是什么?

发布于 2024-10-08 10:24:03 字数 387 浏览 0 评论 0原文

我有一个返回 20,000 多条记录的 sql 过程,并希望将此数据放入 CSV 中以进行 SQL2005 批量加载操作。

我认为使用数据集是多余的,因为我只需要转发对数据的只读访问。

现在我有一个数据读取器,但不认为迭代数据读取器是一个好主意,因为它会锁定 Oracle DB,在它完成工作的同时,我会从中获取 20,000 条记录一段时间。

从逻辑上讲,我正在考虑创建数据表中数据的断开连接快照,并使用它来生成我的 csv 文件。

我不经常开发此类 ETL 应用程序,因此我想知道此类操作的黄金标准是什么。

想法?

另外,请允许我提一下,这需要是一个控制台应用程序,因为 CORP 规则不允许链接服务器和任何很酷的东西 - 所以这意味着 SSIS 已经出局了。

i have a sql proc that returns 20,000 + records and want to get this data into a CSV for a SQL2005 bulk load operation.

i think using a data set is overkill since i need only forward only read access to the data.

now i have a data reader but dont think iterating the data-reader is a good idea cause it will lock the oracle DB i am getting the 20,000 records from for some time while its done doing its thing.

logically i am thinking to create a disconnected snapshot of the data in a data table maybe and use that to generate my csv file.

i dont often develop such ETL apps so i wanted to know whats the gold standard on this type of operation.

thoughts?

also, allow me to mention that this needs to be a console app since CORP rules wont allow linked servers and anything cool - so that means SSIS is out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戈亓 2024-10-15 10:24:03

由于您担心自己进行数据读取器的迭代,我建议使用 SqlBulkCopy 类。

它允许您从任何可以使用 IDataReader 实例读取的源将数据加载到 SQL Server 数据库中,

可能会解决您潜在的锁定问题。

Since you are worried about doing the iteration of the datareader yourself i could recommend using SqlBulkCopy class.

It lets you load data into an sql server database from any source than can be read with an IDataReader instance

Might solve your potential locking issue.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文