Exemplo n.º 1
0
        private DBSession CreateDBSession(string Constr)
        {
            IDbConnection connection = null;
            string        strConn    = DBKeys.GetConnectionString(Constr);

            connection = new System.Data.SqlClient.SqlConnection(strConn);

            return(new DBSession(connection));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取数据库链接实例
        /// </summary>
        /// <param name="name">appSetting节点名</param>
        /// <returns></returns>
        public static SqlConnection GetOpenConnection(string connectionName)
        {
            try
            {
                string connString = DBKeys.GetConnectionString(connectionName);
                if (string.IsNullOrWhiteSpace(connString))
                {
                    throw new Exception("The database connection config error.");
                }

                var connection = new SqlConnection(connString);
                connection.Open();
                return(connection);
            }
            catch (Exception ex)
            {
                throw new Exception("Can not be connected to the data server.", ex);
            }
        }