Click here to Skip to main content
11,496,146 members (369 online)
The site is currently in read-only mode for maintenance. Posting of new items will be available again shortly.
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.
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

1 solution

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:[^].

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.

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=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
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 Sergey Alexandrovich Kryukov 10,401
1 OriginalGriff 8,910
2 Sascha Lefèvre 3,899
3 Maciej Los 3,422
4 Richard Deeming 2,600

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 23 Jun 2011
Copyright © CodeProject, 1999-2015
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