将文件的二进制数据转换为文件并将其保存到特定位置 [英] Convert Binary Data of a file into file and Save it to particular location

查看:184
本文介绍了将文件的二进制数据转换为文件并将其保存到特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在SQl DB中以二进制格式存储了一些文件(图像,文档,PDF)。现在我想写一个S.P.将这些文件从二进制转换为文件并将其保存到指定的位置。怎么做。



我用的是这个代码



DECLARE @Command NVARCHAR(4000)

SET @Command ='bcpSELECT DocumentBinary FROM Apvx_Biot.Reports.Document其中DocumentID = 100042queryoutC:\ biot\Test1.pdf-T -n -Svm-dev-sql -Uxyz -Pxyz'



PRINT @Command - 调试



EXEC xp_cmdshell @Command



此查询工作正常并将PDF导出到服务器的指定C位置但现在我想要提供服务器名称或IP而不是任何驱动器在服务器中我有一个共享文件夹像文件夹名称是biot,我该怎么做????



问候

拉曼

Hi All,

I have some files (Image, Docs,PDF) stored in the format of Binary in the SQl DB. Now I want to write an S.P. to convert these File from Binary to file and Save it to specified Location. How to do that.

I am using this code

DECLARE @Command NVARCHAR(4000)
SET @Command = 'bcp "SELECT DocumentBinary FROM Apvx_Biot.Reports.Document where DocumentID = 100042" queryout "C:\biot\Test1.pdf" -T -n -Svm-dev-sql -Uxyz -Pxyz'

PRINT @Command -- debugging

EXEC xp_cmdshell @Command

This query is working fine and exporting the PDFs to specified C location of the server but now I want give the server name or IP instead of any drive inthat server I have one shared folder like folder name is biot , How can I do this ????

Regards
Raman

推荐答案

我会用(例如) C#代码(你会在网上找到很多exaples)。

但是,我认为这个 Stack Overflow 问题可能会让您感兴趣:通过存储过程从SQL导出二进制文件数据(图像) [ ^ ]。
I would do that with (for instance) C# code (you would find many many exaples on the web).
However, I suppose this Stack Overflow question might interest you: "Exporting binary file data (images) from SQL via a stored procedure"[^].


这是MSDN的链接:

http://msdn.microsoft.com/en-us/library/ms162802(v=SQL.105).aspx [ ^ ]



此相同材料的BOL页面显示各种/ S / U / P和/ T bcp开关通话。机会是bcp实际上可以做你想做的事情,原样。



或许值得注意:

如果密码开头连字符( - )或正斜杠(/),不要在-P和密码之间添加空格



bcp的替代方法... CLR程序集;可能是最好的解决方案:

http://www.codeplex.com/site/search?query=SQL%20CLR&sortBy=Relevance&licenses=|&ac=2 [ ^ ]

SQL CLR导出功能很酷,SQLSERVER& .NET CLR LIBRARIES AND UTILITIES也可能在这里工作。



CLR唯一的缺点是你必须做的所有TSQL写作......
Here's a link to MSDN:
http://msdn.microsoft.com/en-us/library/ms162802(v=SQL.105).aspx[^]

The BOL page for this same material shows all sorts of /S /U /P and /T bcp switch talk. Chances are bcp can actually do what you want it to do, as-is.

Perhaps of note:
"If password begins with a hyphen (-) or a forward slash (/), do not add a space between -P and the password"

Alternative approach to bcp ... CLR assemblies; probably the best solution:
http://www.codeplex.com/site/search?query=SQL%20CLR&sortBy=Relevance&licenses=|&ac=2[^]
"SQL CLR EXPORT FUNCTIONS" is cool and "SQLSERVER & .NET CLR LIBRARIES AND UTILITIES" might work here too.

The only downside to CLR is all the TSQL writing you've got to do ...


这篇关于将文件的二进制数据转换为文件并将其保存到特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆