void p_OutputDataReceived(object sender, DataReceivedEventArgs e) { if (e.Data != null) { if (Regex.Match(e.Data, config.Default.RegexErrorFilterOracle, RegexOptions.IgnoreCase).Success) { _script.Success = false; OnStepProgress(string.Empty, e.Data); if (Regex.Match(e.Data, config.Default.RegexErrorFilterOracleCompilation, RegexOptions.IgnoreCase).Success) { string cmd = "set linesize 150\r\ncol name format a32\r\ncol line format 99999\r\ncol text format a90\r\n"; cmd = string.Format("{0}select name , line, Text\r\nfrom user_errors ue inner join user_objects uo on ue.name=uo.object_name \r\nwhere uo.last_ddl_time > sysdate - 1;\r\n", cmd); cmd = string.Format("{0}exit;", cmd); string connectionMinusPassword = string.Empty; string arguments = GetConnectionString(_currSchema, _cs.Instance, _cs.Port, _cs.Database, ref connectionMinusPassword); arguments = string.Format("-s -r 3 {0}", arguments); Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); p.OutputDataReceived += p_OutputDataReceived; p.ErrorDataReceived += p_ErrorDataReceived; p.Start(); p.StandardInput.WriteLine(cmd); p.BeginOutputReadLine(); p.BeginErrorReadLine(); p.WaitForExit(); } } else { OnStepProgress(string.Empty, e.Data); } } }
public void RunScript(string script, string schema, bool isFile, IConnectionSettings cs) { OnStepProgress("RunScript", string.Format("On Schema {0}", schema)); _currSchema = schema; OracleConnectionSettings ocs = (OracleConnectionSettings)cs; string cmd = isFile ? string.Format(" @\"{0}\"", script) : string.Empty; string connectionMinusPassword = string.Empty; string arguments = GetConnectionString(schema, ocs.Instance, ocs.Port, ocs.Database, ref connectionMinusPassword); arguments = string.Format("{0}{1}", arguments, cmd); _p = ScriptProcessorUtil.CreateProcess(_exe, arguments); _p.StartInfo.EnvironmentVariables.Add("SQLPATH", Alphaleonis.Win32.Filesystem.Path.GetShort83Path(PathHelper.CachePath)); _p.StartInfo.EnvironmentVariables.Add("NLS_LANG", WorkflowParameters.NLS_LANG); _p.OutputDataReceived += p_OutputDataReceived; _p.ErrorDataReceived += p_ErrorDataReceived; _p.StartInfo.WorkingDirectory = Path.GetDirectoryName(Properties.Settings.Default.SqlPlusPath); if (_script.ShowSqlInOutput) { string scriptText = script; if (isFile) { scriptText = File.ReadAllText(script); } OnStepProgress(string.Empty, scriptText); } _p.Start(); if (!isFile) { _p.StandardInput.WriteLine(script); } _p.StandardInput.WriteLine("Exit"); #region read this // best practice information on accessing stdout/stderr from mdsn article: // https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput%28v=vs.110%29.aspx // Do not wait for the child process to exit before reading to the end of its redirected stream. // Do not perform a synchronous read to the end of both redirected streams. // string output = p.StandardOutput.ReadToEnd(); // string error = p.StandardError.ReadToEnd(); // p.WaitForExit(); // Use asynchronous read operations on at least one of the streams. #endregion _p.BeginOutputReadLine(); _p.BeginErrorReadLine(); _p.WaitForExit(); }
static public ConnectionValidationResult ValidateConnectionSettings(SqlServerConnectionSettings cs) { bool ok = true; string msg = "Connection ok."; string stdErr = string.Empty; string cmd = " -Q \"select getdate();\""; string arguments = string.Format("-S {0} -d {1} -E {2}", cs.Instance, cs.Database, cmd); Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); try { p.Start(); p.BeginErrorReadLine(); string stdOut = p.StandardOutput.ReadToEnd(); p.WaitForExit(); if (Regex.Match(stdOut, config.Default.RegexErrorFilterSqlServer, RegexOptions.IgnoreCase).Success) { ok = false; msg = stdOut; } } catch (Exception ex) { if (ex != null) { // msg = p.StandardError.ReadToEnd(); --This was old error information. Changed to OracleScriptProcessor version msg = stdErr; msg += ex.Message; } ok = false; } return(new ConnectionValidationResult(ok, msg)); }
static ConnectionValidationResult ValidateConnectionSettings(string arguments) { bool ok = true; string msg = "Connection ok."; string stdErr = string.Empty; string cmd = "\r\n\r\nselect * from global_name;\r\nexit;"; Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); try { p.Start(); p.StandardInput.WriteLine(cmd); //stdErr = p.StandardError.ReadToEnd(); string stdOut = p.StandardOutput.ReadToEnd(); p.WaitForExit(); if (Regex.Match(stdOut, config.Default.RegexErrorFilterOracle, RegexOptions.IgnoreCase).Success) { ok = false; msg = stdOut; } } catch (Exception ex) { if (ex != null) { msg = stdErr; msg += ex.Message; } ok = false; } return(new ConnectionValidationResult(ok, msg)); }
override public void RunScript(string script, bool isFile, IConnectionSettings cs) { string cmd = isFile ? string.Format("-i \"{0}\"", script) : string.Format("-Q \"{0}\"", script); string arguments = string.Format("-S {0} -d {1} -E {2} {3} {4} {5}", cs.Instance, cs.Database, _script.ShowSqlInOutput ? "-e" : string.Empty, _script.FailBranchOnError ? "-b" : string.Empty, _script.SetQuotedIdentifier ? "-I" : string.Empty, cmd); Process p = ScriptProcessorUtil.CreateProcess(_exe, arguments); p.OutputDataReceived += p_OutputDataReceived; p.ErrorDataReceived += p_ErrorDataReceived; p.Start(); #region read this // best practice information on accessing stdout/stderr from mdsn article: // https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput%28v=vs.110%29.aspx // Do not wait for the child process to exit before reading to the end of its redirected stream. // Do not perform a synchronous read to the end of both redirected streams. // string output = p.StandardOutput.ReadToEnd(); // string error = p.StandardError.ReadToEnd(); // p.WaitForExit(); // Use asynchronous read operations on at least one of the streams. #endregion p.BeginOutputReadLine(); string error = p.StandardError.ReadToEnd(); p.WaitForExit(); }