Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: CLR
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.
Posted 17-May-11 10:22am
Edited 23-Jun-11 4:07am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

There is no such thing as "DOS Batch file" anymore! How much longer shall we see such questions about something which does not exist.
Batch files are batch files; there is nothing of DOS in them. By the way, the syntax became more advanced compared to DOS time; writing batch became considerably easier (for example, there are procedures now).
 
Now, you don't need to run this Process. Running external processes can be used only as a last resort. You need to get the files in your application code:
 
string[] files = System.IO.Directory.GetFiles(myDirectory);
 
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.
 
—SA
  Permalink  
Comments
Jeff Pufnock at 23-Jun-11 9:06am
   
Thank you for your reply. Executing System.IO.Directory.GetFiles resulted in what looks like a security error (below). Do you know of a setting that could be changed to fix this? Thanks - Jeff
 
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 for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
System.Security.SecurityException:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.Directory.InternalGetFileDirectoryNames(String path, String userPathOriginal, String searchPattern, Boolean includeFiles, Boolean includeDirs, SearchOption searchOption)
at System.IO.Directory.GetFiles(String path, String searchPattern, SearchOption searchOption)
at System.IO.Directory.GetFiles(String path)
at T_Ware_SQL.StoredProcedures.RunVIIMPORT()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 George Jonsson 215
1 Kornfeld Eliyahu Peter 169
2 Zoltán Zörgő 139
3 PIEBALDconsult 130
4 OriginalGriff 120
0 OriginalGriff 6,165
1 DamithSL 4,658
2 Maciej Los 4,107
3 Kornfeld Eliyahu Peter 3,649
4 Sergey Alexandrovich Kryukov 3,342


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 23 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100