【发布时间】:2015-12-03 16:57:47
【问题描述】:
我有一个将 sqlcmd.exe 作为进程启动的 ASP .NET 应用程序。在我们三个测试环境中的两个中,我们没有问题。但是,在第三台机器上,即使 sqlcmd.exe 与客户端连接工具一起安装,Process.exe 也找不到 sqlcmd.exe。显示的错误是:
Error running process: System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at L3_CNM.Utilities.Common.SqlcmdHelper.RunRemoteScript(String ServerAddress, String datbaseName, String filePath, String outputFilePath
我不知道为什么会发生这种情况。一切正常的情况与失败的情况之间的区别是:
1) 当它工作时,有一个完整的 SQL 服务器安装。当它失败时,我们只是将 sqlcmd 作为下载的安装包安装,它指向驻留在其他地方的 SQL 服务器。
2) 当它工作时,应用程序从与 Windows 安装相同的磁盘卷运行。在失败的机器上,应用程序安装在 Windows 安装的另一个卷上。
其他关键点 - PATH 变量显示 sqlcmd.exe 的位置,作为应用程序池身份的用户是本地系统管理员的一部分,当通过命令提示符运行 sqlcmd.exe 时,结果是预期的。
任何帮助将不胜感激。
谢谢
编辑:添加代码:
try
{
Process process = new Process();
process.StartInfo.FileName = "sqlcmd.exe";
Logging.Instance.Log(Logging.Levels.Message, "Process start arguments: " + process.StartInfo.Arguments);
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
if (process.Start())
Logging.Instance.Log(Logging.Levels.Message, "Process successfully started");
else
{
Logging.Instance.Log(Logging.Levels.Message, "Unable to start process");
}
string output = process.StandardOutput.ReadToEnd();
output += process.StandardError.ReadToEnd();
process.WaitForExit();
Logging.Instance.Log(Logging.Levels.Message, "Process exited with output: " + output);
return output;
}
catch (Exception e)
{
Logging.Instance.Log(Logging.Levels.Error, "Error running process: " + e.ToString());
return e.ToString();
}
【问题讨论】:
-
我们也不知所措,没有看到您的代码,谁能准确地回答这个问题。这可能有多种原因。也许其中一个非工作环境的设置不完全像 2工作环境..有点像在黑暗中射击并期望每次都能击中靶心..请提供更有意义的信息或代码..你能展示你如何指向其他sql服务器吗..?
-
@MethodMan,我现在不关心 SQL 连接是否成功,我只是想达到 SQLCMD 执行的地步。我试图提供尽可能多的信息,但我已经用用于执行 SQLCMD 的代码更新了原始问题。
-
对不起间距!感谢@MethodMan 修复它
-
你的问题在这里
process.StartInfo.FileName = "sqlcmd.exe";也许你可以在.config 文件中添加一个条目sqlcmd.exe所在的位置.. 很明显你的Environment Variables有问题为什么不你不是从工作机器和非工作机器复制过去的环境变量到文本编辑器并比较路径 -
还有那台不工作的机器你试过让他们在添加环境变量后做一个简单的
Reboot吗?只是好奇
标签: c# asp.net windows-server-2012 filenotfoundexception sqlcmd