.net – System.Diagnostics.Process.Start() gives access denied when running from WCF service

asp.net-mvcnetwcfwindows 7windows-server-2008

I have a WCF service that calls a class that uses Process.Start(startInfo) to execute SQLPackage.exe which is the SQL Server Data Tools DACPAC execution utility. If I access this code via a WPF test harness running in the debugger, it works as designed. However, once the WCF service is running in IIS the line of code that calls Process.Start(startInfo) fails with an "Access is denied" message.

I have made several attempts to resolve this; I added impersonation, I added the "runas" verb to the startInfo, I have changed both the app pool and the application hosting the service use a domain account with administrator privileges, I have verified that the SQLPackage.exe is permitted for that domain account in question, I have messed with the User Account Control settings — nothing has worked, I get the same exact error every time.

Unless there is some inherent restriction against a WCF service calling an executable via Process.Start(), it seems to me this has to be some kind of configuration issue but I'm pretty stumped at this point. My machine is running Windows 7, our server is W2K8, both are having the same behavior. The client calling the service is ASP.NET MVC, though I'm not sure that would matter.

Does anyone know what I need to do to get this to execute successfully as a WCF service running in IIS? I've read a lot of threads on various sites on similar topics but they mostly pertained to windows services and older operating systems and I never got any of those suggestions to work. Thanks in advance! If you need more information please let me know.

Here is my code:

            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = DacPacExecutablePath;
            startInfo.Arguments = FormDacPacArgumentString(dbname, server);
            startInfo.WindowStyle = ProcessWindowStyle.Hidden;
            startInfo.UseShellExecute = false;
            startInfo.Verb = "runas";
            startInfo.CreateNoWindow = true;
            startInfo.RedirectStandardOutput = true;
            using (Process process = Process.Start(startInfo)) //error on this line I think.
            {
              using (StreamReader reader = process.StandardOutput)
              {
                string result = reader.ReadToEnd();
                //do stuff
              }
            }

Here is the error:

Message : Access is denied
Source : System
Stacktrace : at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at MatterDBGenerator.DoGenerateDB(string dbname, InstallationServer server) in c:\projects\pathstuff\MatterDBGenerator.cs:line 107
at MatterDBGenerator.GenerateMatterDatabase(String dbname, InstallationServer server) in c:\projects\pathstuff\MatterDBGenerator.cs:line 86
TargetSite : Boolean StartWithCreateProcess(System.Diagnostics.ProcessStartInfo)

Best Answer

The problem was that I was pointing to a directory, not to a file. Yes, it did have execute permissions. StartInfo.FileName was pointing to "C:\Program Files (x86)\Microsoft Sql Server\110\dac\bin" instead of "C:\Program Files (x86)\Microsoft Sql Server\110\dac\bin\SQLPackage.exe". Obviously you can't execute a directory, but for some reason Visual Studio managed to "guess" which executable to run when I was in the debugger pointing to the SQL Server bin, but not when the file was copied to an IIS directory, at which point I noticed the startInfo.filename had a directory instead of a file.

Related Topic