当前位置: 移动技术网 > IT编程>开发语言>.net > c# 大批量用户访问时报错【PetaPoco】

c# 大批量用户访问时报错【PetaPoco】

2018年06月06日  | 移动技术网IT编程  | 我要评论

傅泽星,教师节黑板报素材,胡锦朝

报错信息:There is already an open DataReader associated with this Connection which must be closed first

缓解的方案:在实例化database的时候利用线程独立实例化,每个线程一个单独的database实例

 

        [ThreadStatic]
        private static Database _threadInstance = null;

        protected Database DB = CreateDatabase();

        public static Database CreateDatabase()
        {
            if (_threadInstance == null)
            {
                _threadInstance = new Database(connectionStr);
            }
            return _threadInstance;
        }

 

随笔记录。

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网