欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-12-25 09:27:17
报错信息:There is already an open DataReader associated with this Connection which must be closed first 缓解的方案:在实例化database的时候利用线程独立实例化,每个线程一个单独的database实例 ......

报错信息: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;
        }

 

随笔记录。