隐的博客

计算机改名对SQLSERVER的影响和解决方法

影响

  1. 不能用新的计算机名 连接
  2. 不能使用复制功能
  3. 数据库维护计划就不能运行
  4. 无法连接本地reporting services
  5. 等等其他问题


解决方法:

先用 sp_dropserver 删除服务器,语句:EXEC sp_dropserver '老计算机名'

再用 sp_addserver 添加新的服务器,语句:EXEC SP_ADDSERVER '新计算机名','LOCAL'

最后重启SQL SERVER 服务,问题解决。

 

分布式唯一ID生成器Twitter 的 Snowflake idworker C#版

直接上代码

public class IdWorker
    {
        //机器标识位数
        private const int WORKER_ID_BITS = 4;
        //机器标识位的最大值
        private const long MAX_WORKER_ID = -1L ^ -1L << WORKER_ID_BITS;
        //毫秒内自增位
        private const int SEQUENCE_BITS = 10;
        //自增位最大值
        private const long SEQUENCE_Mask = -1L ^ -1L << SEQUENCE_BITS;
        private const long twepoch = 1398049504651L;
        //时间毫秒值向左偏移位
        private const int timestampLeftShift = SEQUENCE_BITS + WORKER_ID_BITS;
        //机器标识位向左偏移位
        private const int WORKER_ID_SHIFT = SEQUENCE_BITS;
        private static readonly DateTime START_TIME = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
        private static readonly object LOCK = new object();
        private long sequence = 0L;
        private long lastTimestamp = -1L;
        private long workerId;
        public IdWorker(long workerId)
        {
            if (workerId > MAX_WORKER_ID || workerId < 0)
            {
                throw new ArgumentException(string.Format("worker id can't be greater than {0} or less than 0", MAX_WORKER_ID));
            }
            this.workerId = workerId;
        }
        /// <summary>
        /// 获取下一个id值
        /// </summary>
        /// <returns></returns>
        public long NextId()
        {
            lock (LOCK)
            {
                long timestamp = TimeGen();
                //当前时间小于上一次时间,错误
                if (timestamp < this.lastTimestamp)
                {
                    throw new Exception(string.Format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
                }
                //当前毫秒内
                if (this.lastTimestamp == timestamp)
                {
                    //+1 求余
                    this.sequence = (this.sequence + 1) & SEQUENCE_Mask;
                    //当前毫秒内计数满了,等待下一秒
                    if (this.sequence == 0)
                    {
                        timestamp = tilNextMillis(lastTimestamp);
                    }
                }
                else      //不是当前毫秒内
                {
                    this.sequence = 0;   //重置当前毫秒计数
                }
                this.lastTimestamp = timestamp;
                //当前毫秒值 | 机器标识值 | 当前毫秒内自增值
                long nextId = ((timestamp - twepoch << timestampLeftShift))
                | (this.workerId << WORKER_ID_SHIFT) | (this.sequence);
                return nextId;
            }
        }
        /// <summary>
        /// 等待下一个毫秒
        /// </summary>
        /// <param name="lastTimestamp"></param>
        /// <returns></returns>
        private long tilNextMillis(long lastTimestamp)
        {
            long timestamp = TimeGen();
            while (timestamp <= lastTimestamp)
            {
                timestamp = TimeGen();
            }
            return timestamp;
        }
        /// <summary>
        /// 获取当前时间的Unix时间戳
        /// </summary>
        /// <returns></returns>
        private long TimeGen()
        {
            return (DateTime.UtcNow.Ticks - START_TIME.Ticks) / 10000;
        }
    }

VS扩展【备忘】

Auto Deploy

Bootstrap Snippet Pack

Bundler & Minifier

ClaudialIDE

Clean & Rebuild

Glyphfriend

Indent Guides

jQuery Code Snippets

VSColorOutput

Web Essentials