Example #1
0
        /// <summary>
        /// 设置连接
        /// </summary>
        /// <param name="db"></param>
        private void SettingConnection(SqlSugarClient db)
        {
            try
            {
                lock (this.tranLock)
                {
                    if (Tran != null)
                    {
                        lock (this.Tran)
                        {
                            lock (db)
                            {
                                db.GetConnection().EnlistTransaction(Tran);
                            }
                        }
                    }
                }
            }
            catch (Exception)//BUG 实现找不到为什么锁了还有时会报被占用
            {
                try
                {
                    System.Threading.Thread.Sleep(10);
                    db.GetConnection().EnlistTransaction(Tran);
                }
                catch (Exception)
                {
                    try
                    {
                        System.Threading.Thread.Sleep(100);
                        db.GetConnection().EnlistTransaction(Tran);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            System.Threading.Thread.Sleep(1000);
                            db.GetConnection().EnlistTransaction(Tran);
                        }
                        catch (Exception)
                        {
                            System.Threading.Thread.Sleep(10000);
                            db.GetConnection().EnlistTransaction(Tran);
                        }
                    }
                }
            }

            lock (this.dbsLock)
            {
                if (dbs != null)
                {
                    lock (dbs)
                    {
                        dbs.Add(db);
                    }
                }
            }
        }