如何使用SQL CLR存储过程压缩文件 [英] How to zip files using SQL CLR store procedure

查看:74
本文介绍了如何使用SQL CLR存储过程压缩文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你是.Net的新手。根据我的业务要求,我必须根据数据表帐号列中的文件名压缩文件。如果文件名匹配,我们有拉链总匹配文件和密码保护。我编写了压缩文件的代码。它在控制台应用程序中工作。不在CLR存储过程中工作。执行存储过程时获取错误。



。在执行用户定义的例程或聚合期间发生.Net框架错误。系统security.security异常



我允许DLL作为外部访问权限。



什么我试过了:



这是我的压缩文件夹的代码。

 Sting path =  @  c:\ program Files \ 7z\7z.exe; 

字符串 Destinationfolder = @ d:\temp\;
字符串源文件夹= @ E: \myfiles.zip;

Processstartinfo pro = new processstartinfo( cmd.exe的);
流程p = process();
Pro.windowstyle = processwindowstyle.hidden;
Pro.filename = path;
Pro.arguments = a -p passwordd + \ +目标文件夹+ \ +源文件夹+ \;
流程x =流程开始(专业);
X.waitforexit();
Int status = x.exitcode;



我在代码中的错误是什么。我正在使用.Net框架4



感谢您提前

解决方案

因为您正在开始一个新流程,不只是使用文件等,尝试将程序集定义为 UNSAFE 而不是 EXTERNAL_ACCESS



根据您的具体情况,您可能还需要设置 TRUSTWORTHY数据库属性 [ ^ ] on。

是。它正在发挥作用。您能否简要介绍一下外部访问,安全,不安全。我们在哪些情况下使用外部访问,或安全或不安全。感谢您提前


Hi am new to .Net. as per my business requirements I have to zip the files based on filename in data table account number column. If file name is matched ,we have zip total matched files with password protection. I wrote code to zip files .It's working in console application. Not in working in CLR stored procedure. While executing store procedure getting error.

.Net framework error occurred during execution of user defined routine or aggregate . System security.security exception

I given permission to DLL as external access.

What I have tried:

Here is my code for zipping folder.

Sting path= @"c:\program files\ 7z\7z.exe";

String Destinationfolder=@"d:\temp\";
String Source folder=@"E:\myfiles.zip";

Processstartinfo pro= new processstartinfo ("cmd.exe");
Process p=new process ();
Pro.windowstyle= processwindowstyle.hidden;
Pro.filename= path;
Pro.arguments="a -p passwordd+ "\""+Destination folder+"\""+ source folder+"\"";
Process x= process start(pro);
X.waitforexit();
Int status= x.exitcode;


What's is my mistake in code. Am using .Net framework 4

Thanks for advance

解决方案

Since you're starting a new process, not just using files etc, try defining the assembly as UNSAFE instead of EXTERNAL_ACCESS

Depending on your situation, you may also need to set TRUSTWORTHY Database Property[^] on.


Yes. It's working. Can you give brief description on external access, safe,unsafe. In which Cases we have go with external access, or safe or unsafe. Thanks for advance


这篇关于如何使用SQL CLR存储过程压缩文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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