zoukankan      html  css  js  c++  java
  • DbUtils

    `

     public class DbUtils
    {
        private static object _obj = new object();
        private static IDbConnection _connection = null;
        public static IDbConnection Main
        {
            get
            {
                IDbConnection dbContext = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);
                return dbContext;
            }
        }
        public static SQLiteConnection SqliteConnection
        {
            get
            {
                SQLiteConnectionStringBuilder sb = new SQLiteConnectionStringBuilder();
                sb.DataSource = Configs.DbPath;
                sb.Version = 3;
                sb.Password = Configs.DbPassWord;
                SQLiteConnection connection = null;
    
                if (connection == null)
                {
                    lock (_obj)
                    {
                        if (connection == null)
                        {
                            connection = new SQLiteConnection(sb.ToString());
                        }
                    }
                }
                return connection;
            }
        }
        /// <summary>
        /// using写法
        /// </summary>
        public static IDbConnection SqlServerConnection
        {
            get
            {
                IDbConnection connection = null;
                if (connection == null)
                {
                    lock (_obj)
                    {
                        if (connection == null)
                        {
                            connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);
                        }
                    }
                }
                return connection;
            }
        }
        /// <summary>
        /// 单例
        /// </summary>
        /// <returns></returns>
        public static IDbConnection SqlServerInstance()
        {
            if (_connection == null)
            {
                lock (_obj)
                {
                    if (_connection == null) // double-check
                    {
                        _connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Default"].ConnectionString);
                    }
                }
            }
            return _connection;
        }
    }
    

    `

  • 相关阅读:
    运营活动总结
    《天天来塔防》游戏分析
    C++ 头文件与using namespace std
    cocos2dx -- 错误笔记(4)ntdll.dll堆已损坏
    大学,且行且珍惜
    cocos2dx -- 错误笔记(3)class类型重定义
    谈谈对HTML语义化的理解
    CSS深入研究:display的恐怖故事解密(2)
    We have a problem with promises
    react-组件生命周期
  • 原文地址:https://www.cnblogs.com/wangyinlon/p/13888924.html
Copyright © 2011-2022 走看看