将图像从sql导出到文件

时间:2012-01-13 13:42:01

标签: c# sql-server-2008 tsql

我有大量的图像(超过16,000)在SQL中,我需要导出到文件。我已经阅读了这个线程How can I export images from SQL Server to a file on disk?,这似乎是我想要做的,但答案是指这个线程How to save an image from SQL Server to a file using SQL实际上通过电子邮件发送图像而不是保存它们。由于缺乏SQL经验,我在这方面遇到了麻烦。我想知道这是否可以在SQL中完成,或者我是否需要编写.NET应用程序来提取信息。

我正在考虑这些问题:

select imageName, image from table where blah blah blah --(returns table of over 16,000 images).
--do whatever it takes to save each image in a file with filename = imageName

非常感谢任何帮助。

3 个答案:

答案 0 :(得分:1)

您可以使用bcp Utility执行此操作。

答案 1 :(得分:1)

听起来像是ETL(提取变换加载)过程。在这种情况下,我建议http://hibernatingrhinos.com/open-source/rhino-etl。构建流程并处理操作。 rhino.etl是MSSqls DTS和SSIS的替代品。

我看到的最重要的事情是你不想一次将所有16000条记录加载到内存中,而是一次一条地传输记录以保持低内存消耗。

答案 2 :(得分:0)

我最终编写了一个C#应用程序,它使用http://www.redmondpie.com/inserting-in-and-retrieving-image-from-sql-server-database-using-c/中的代码来写出图像。我编写了应用程序来抓取用户设置的批量大小的图像,最后在一个多小时内写出了大约30,000张图像。感谢您的建议。