sql - clr project using processes -


i'm stuck many days on problem.

till used xp_cmdshell in on 40 stored procedures. want replace calls using assemblies. create clr project. looks :

using system; using system.data; using system.data.sqltypes; using system.diagnostics; using system.io; using system.text; using microsoft.sqlserver.server;  namespace cmdshellbridge {     public class cmdshell     {         [sqlprocedure]         public static void cmdshellbridgebcp(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgemd(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgemkdir(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgebcmsyncimport(string arguments, out string returnmessage)         {             processnotcmd("f:\\thirdparty_applications\\bcmsync\\bcmsyncimp.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgebcmsyncexport(string arguments, out string returnmessage)         {             processnotcmd("f:\\thirdparty_applications\\bcmsync\\bcmsyncexp.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgeosql(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgesqlcmd(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgedir(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgexcopy(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgedel(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgenetuse(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgemove(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgecopy(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgeblat(string arguments, out string returnmessage)         {             processnotcmd("d:\\emailer\\blat.exe", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgerobocopy(string arguments, out string returnmessage)         {             processnotcmd("robocopy", arguments, out returnmessage);         }          [sqlprocedure]         public static void cmdshellbridgerd(string arguments, out string returnmessage)         {             processcmd("cmd.exe", arguments, out returnmessage);         }          private static void processcmd(string filename, string arguments, out string returnmessage)         {             try             {                 process proc = new process();                 proc.startinfo.filename = filename;                 proc.startinfo.arguments = arguments;                 proc.startinfo.useshellexecute = true;                 proc.start();                 proc.waitforexit();                 returnmessage = "ok";             }             catch (exception ex)             {                 returnmessage = ex.message;             }          }          private static void processnotcmd(string filename, string arguments, out string returnmessage)         {             try             {                 process proc = new process();                 proc.startinfo.filename = filename;                 proc.startinfo.arguments = arguments;                 proc.start();                 proc.waitforexit();                 returnmessage = "ok";             }             catch (exception ex)             {                 returnmessage = ex.message;             }          }      } } 

and in stored procedure use procedures in case:

set     @execcommand = ' \c bcp ' + @cssdbname+'.bankcardtrxgpetemp in '+@importdir + @kfilename +' -c -s'+@cssserver+' -r \n -t -c 1250 -e '+@importdir+'bcp.error -m 1000 >nul'  declare @sresult nvarchar(max)  exec    dbo.cmdshellbridgebcp @execcommand, @sresult output 

if try execute this, result "ok", in fact nothing ok, because used bcp command doesn't import anything. same result if try use dos commands, dir, del, mkdir. result ok, nothing executed in fact.

my assemblies permission set set unrestricted. maybe problem have use network shared folders in commands ? when used mkdir local folder, works ok.

but in shared folders have full permissions.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -