SQLCMD未找到从ASP .NET
运行过程时我有sqlcmd.exe开始作为一个过程的ASP .NET应用程序。在我们三个测试环境中的两个中,我们没有任何问题。但是,在第三台计算机上,即使sqlcmd.exe与客户端连接工具一起安装,Process.exe也找不到sqlcmd.exe。显示的错误是:SQLCMD未找到从ASP .NET
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 Server安装。当它失败时,我们只安装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();
}
一个简单的重新启动。有时候,我讨厌Windows。
感谢@Methodman的意见。
我想这是对PATH环境变量。
几个测试!一,打开命令窗口,键入
WHERE SQLCMD
这将随时随地打印出SQLCMD可以看出。如果你什么都得不到,你需要更新你的路径。如果你得到的东西,它可能是一个用户环境变量,而不是系统环境变量,这是ASP.NET将使用的。
您能查看这个变量的系统版本包含了正确的文件夹?在win8及以上版本中,打开开始菜单并键入“编辑系统环境变量”。然后单击“环境变量”并确保在“系统变量”下的PATH包含由WHERE SQLCMD
返回的文件夹。如果没有,请将其放入,并用分号与其他文件夹分开。
我已手动查看以查看sqlcmd.exe所在的位置,并验证该文件夹位于PATH系统变量中,我将不会看到SQLCMD返回并验证该位置。谢谢! – Rishi
我们正处在一个太亏了,没有看到你的代码的任何人都可以准确地回答这个..这可能是多种原因..也许非工作环境的一个没有设置完全一样的2个工作环境..样像在黑暗中拍摄,并期望每次打到靶心..请提供更有意义的信息或代码..你能展示你如何指向其他SQL服务器..? – MethodMan
@MethodMan,我现在不在意SQL连接是否成功,我只是试图达到SQLCMD执行的目的。我试图提供尽可能多的信息,但我已经使用用于执行SQLCMD的代码更新了原始问题。 – Rishi
抱歉,关于间距!感谢@MethodMan修复它 – Rishi