Ejemplo n.º 1
0
        private DataTable SafeSelect(string sql)
        {
            try
            {
                return(_db.ExecuteDataTableSQL(sql, null));
            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                if (_errors.ContainsKey(ex.Number))
                {
                    _errors[ex.Number].count++;
                }
                else
                {
                    sqlerror error = new sqlerror();
                    error.count   = 1;
                    error.sql     = sql;
                    error.Message = ex.Message;
                    _errors.Add(ex.Number, error);
                }
            }

            return(null);
        }
Ejemplo n.º 2
0
        private void GetAllDBs()
        {
            List<string> searchlist;

            string connstr;
            string sql;
            string provider = cbProvider.SelectedValue.ToString();

            // Get database names
            if (provider == "System.Data.SqlClient")
            {
                if (cbSQLLogin.Checked)
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=False; User ID=" + tbUsername.Text + "; Password="******";";
                }
                else
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=True;";
                }
                sql = "select name from sysdatabases order by name";
            }
            else if (provider == "MySql.Data.MySqlClient")
            {
                connstr = "Data Source=" + cbServer.Text + "; Database=information_schema; User ID=" + tbUsername.Text + "; Password="******";";
                sql = "select schema_name name from schemata order by schema_name";
            }
            else  // Unknown provider
            {
                throw new NotImplementedException("Unsupported database provider: '" + provider + "'.");
            }

            System.Data.DataTable dtDBs;

            string dbs = string.Empty;

            using (db mydb = new db(provider, connstr))
            {
                dtDBs = mydb.ExecuteDataTableSQL(sql, null);
            }

            if (cbDBPattern.Checked)
            {
                searchlist = new List<string>();
                foreach (string row in tbDatabases.Text.Replace("\r", "").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    searchlist.Add(row);
                }
            }
            else
                searchlist = null;

            foreach (DataRow drDB in dtDBs.Rows)
            {
                if (searchlist == null)
                {
                    dbs += drDB["name"].ToString() + Environment.NewLine;
                }
                else
                {
                    string dbname = drDB["name"].ToString();

                    foreach (string search in searchlist)
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(
                                        dbname, search, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                        {
                            dbs += dbname + Environment.NewLine;
                            break;
                        }
                    }
                }
            }

            tbDatabases.Text = dbs.TrimEnd();

            return;
        }
Ejemplo n.º 3
0
        private void GetAllDBs()
        {
            List <string> searchlist;

            string connstr;
            string sql;
            string provider = cbProvider.SelectedValue.ToString();


            // Get database names
            if (provider == "System.Data.SqlClient")
            {
                if (cbSQLLogin.Checked)
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=False; User ID=" + tbUsername.Text + "; Password="******";";
                }
                else
                {
                    connstr = "Server=" + cbServer.Text + "; Database=master; Trusted_Connection=True;";
                }
                sql = "select name from sysdatabases order by name";
            }
            else if (provider == "MySql.Data.MySqlClient")
            {
                connstr = "Data Source=" + cbServer.Text + "; Database=information_schema; User ID=" + tbUsername.Text + "; Password="******";";
                sql     = "select schema_name name from schemata order by schema_name";
            }
            else  // Unknown provider
            {
                throw new NotImplementedException("Unsupported database provider: '" + provider + "'.");
            }

            System.Data.DataTable dtDBs;

            string dbs = string.Empty;

            using (db mydb = new db(provider, connstr))
            {
                dtDBs = mydb.ExecuteDataTableSQL(sql, null);
            }


            if (cbDBPattern.Checked)
            {
                searchlist = new List <string>();
                foreach (string row in tbDatabases.Text.Replace("\r", "").Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    searchlist.Add(row);
                }
            }
            else
            {
                searchlist = null;
            }


            foreach (DataRow drDB in dtDBs.Rows)
            {
                if (searchlist == null)
                {
                    dbs += drDB["name"].ToString() + Environment.NewLine;
                }
                else
                {
                    string dbname = drDB["name"].ToString();

                    foreach (string search in searchlist)
                    {
                        if (System.Text.RegularExpressions.Regex.IsMatch(
                                dbname, search, System.Text.RegularExpressions.RegexOptions.IgnoreCase))
                        {
                            dbs += dbname + Environment.NewLine;
                            break;
                        }
                    }
                }
            }

            tbDatabases.Text = dbs.TrimEnd();

            return;
        }