问题描述
希望您能对我的问题有所了解.我部署到Sql Server 2005数据库中的CLR函数除返回零值外不执行任何操作,可以干净地执行.当我尝试执行其中包含一行的Windows批处理文件时(dir> c:\ t-ware \ dirlist.txt),出现以下错误:
消息6522,第16级,状态1,程序RunVIIMPORT,第0行
用户定义的例程或聚合"RunVIIMPORT"的执行过程中发生了.NET Framework错误:
System.Security.SecurityException:请求失败.
System.Security.SecurityException:
在T_Ware_SQL.Utilities.RunMAS90BatchFile()
在T_Ware_SQL.StoredProcedures.RunVIIMPORT()
执行批处理文件的VB代码行是:System.Diagnostics.Process.Start(" d:\ t-ware \ mytest.bat)
另外,执行以下操作具有相同的结果:System.Diagnostics.Process.Start("dir> test.txt")
(我需要执行一个MAS90 Visual Integrator作业,并且它可以从批处理文件工作...只需要能够从Sql Server执行批处理文件即可.)
如果您能提供任何帮助,将不胜感激.谢谢杰夫.
Was hoping you could shed some insight into my problem. My CLR function that I deployed to my Sql Server 2005 database executes cleanly when it does nothing except return a value of zero. When I have it try to execute a Windows Batch file that has a single line in it (dir > c:\t-ware\dirlist.txt) I get the following error:
Msg 6522, Level 16, State 1, Procedure RunVIIMPORT, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "RunVIIMPORT":
System.Security.SecurityException: Request failed.
System.Security.SecurityException:
at T_Ware_SQL.Utilities.RunMAS90BatchFile()
at T_Ware_SQL.StoredProcedures.RunVIIMPORT()
The VB line of code to execute the batch file is: System.Diagnostics.Process.Start(""d:\t-ware\mytest.bat")
Also, did the following with the same results: System.Diagnostics.Process.Start("dir > test.txt")
(I need to execute a MAS90 Visual Integrator job and it works from a batch file...just need to be able to execute the batch file from Sql Server...)
If you could provide any help, it would be greatly appreciated. Thanks, Jeff.
推荐答案
string[] files = System.IO.Directory.GetFiles(myDirectory);
有关其他选项,请参见其他重载的System.IO.Directory.GetFiles
方法:
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx [ ^ ].
切勿使用"d:\t-ware\mytest.bat
"之类的硬编码立即数.您将如何维护它们?特别是,所有目录都应根据您的条目组装位置和/或配置数据计算得出.
For other options, please see other overloaded System.IO.Directory.GetFiles
methods:
http://msdn.microsoft.com/en-us/library/07wt70x2.aspx[^].
Never use hard-coded immediate constants like "d:\t-ware\mytest.bat
". How would you maintain them? In particular, all directories should be calculated our of your entry assembly location and/or configuration data.
这篇关于CLR函数执行Windows批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!