Example #1
0
        ///<summary>Throws Exception.
        ///Checks to see if the computer is allowed to use create table or drop table syntax queries.
        ///Will return false if using replication and the computer OD is running on is not the ReplicationUserQueryServer set in replication setup.
        ///Otherwise true.</summary>
        private static bool IsSafeSqlForReplication(string command)
        {
            if (!PrefC.RandomKeys && !Db.IsAutoIncrementIncrementSetForReplication())             //If replication is disabled, then any command is safe.
            //Previously users could set PrefName.RandomPrimaryKeys but there is no longer a UI for this.
            //PrefName.RandomPrimaryKeys use to be required for replication but this has since changed so we can not rely on this due to replication setup changes.
            {
                return(true);
            }
            bool isSafe = true;

            if (Regex.IsMatch(command, ".*CREATE[\\s]+TABLE.*", RegexOptions.IgnoreCase))
            {
                isSafe = false;
            }
            if (Regex.IsMatch(command, ".*CREATE[\\s]+TEMPORARY[\\s]+TABLE.*", RegexOptions.IgnoreCase))
            {
                isSafe = false;
            }
            if (Regex.IsMatch(command, ".*DROP[\\s]+TABLE.*", RegexOptions.IgnoreCase))
            {
                isSafe = false;
            }
            if (isSafe)
            {
                return(true);
            }
            //At this point we know that replication is enabled and the command is potentially unsafe.
            if (PrefC.GetLong(PrefName.ReplicationUserQueryServer) == 0)           //if no allowed ReplicationUserQueryServer set in replication setup
            {
                throw new ApplicationException("This query contains unsafe syntax that can crash replication.  There is currently no computer set that is allowed to run these types of queries.  This can be set in the replication setup window.");
            }
            else if (!ReplicationServers.IsConnectedReportServer())             //if not running query from the ReplicationUserQueryServer set in replication setup
            {
                throw new ApplicationException("This query contains unsafe syntax that can crash replication.  Only computers connected to the report server are allowed to run these queries.  The current report server can be found in the replication setup window.");
            }
            return(true);
        }