Exemplo n.º 1
0
        public ConnectionSettingsCollection ToSqlServerConnectionSettings()
        {
            //optimistic initialization (IsValid = true)
            ConnectionSettingsCollection list = new ConnectionSettingsCollection()
            {
                IsValid = true
            };

            foreach (DatabaseInstance i in this.DatabaseInstance)
            {
                foreach (Database db in i.Database)
                {
                    SqlServerConnectionSettings cs = new SqlServerConnectionSettings()
                    {
                        Instance = i.Name,
                        Database = db.Name
                    };

                    cs.Validate();
                    if (!cs.IsValid)
                    {
                        list.IsValid = false;
                    }

                    list.Add(cs);
                }
            }

            if (list.Count == 0)
            {
                list.IsValid = false;
            }

            return(list);
        }
Exemplo n.º 2
0
        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));
        }