当前位置: 首页>>代码示例>>C#>>正文


C# IDbFactory.CreateConnection方法代码示例

本文整理汇总了C#中IDbFactory.CreateConnection方法的典型用法代码示例。如果您正苦于以下问题:C# IDbFactory.CreateConnection方法的具体用法?C# IDbFactory.CreateConnection怎么用?C# IDbFactory.CreateConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDbFactory的用法示例。


在下文中一共展示了IDbFactory.CreateConnection方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetConnection

        /// <summary>
        ///		Returns a connection for the current transaction. This will be an existing <see cref="DbConnection"/>
        ///		instance or a new one if there is a <see cref="TransactionScope"/> active. Otherwise this method
        ///		returns null.
        /// </summary>
        /// <param name="db"></param>
        /// <returns>Either a <see cref="DbConnection"/> instance or null.</returns>
        public static DbConnection GetConnection(string connectionString, IDbFactory dbFactory)
        {
            Transaction currentTransaction = Transaction.Current;

            if (currentTransaction == null)
            {
                return null;
            }

            Dictionary<string, DbConnection> connectionList;
            transactionConnections.TryGetValue(currentTransaction, out connectionList);

            DbConnection connection;
            if (connectionList != null)
            {
                connectionList.TryGetValue(connectionString, out connection);
                if (connection != null)
                {
                    return connection;
                }
            }
            else
            {									// We don't have a list for this transaction, so create a new one
                connectionList = new Dictionary<string, DbConnection>();
                lock (transactionConnections)
                {
                    transactionConnections.Add(currentTransaction, connectionList);
                }
            }

            //
            // Next we'll see if there is already a connection. If not, we'll create a new connection and add it
            // to the transaction's list of connections.
            //
            if (connectionList.ContainsKey(connectionString))
            {
                connection = connectionList[connectionString];
            }
            else
            {
                connection = dbFactory.CreateConnection(connectionString);
                connection.Open();
                currentTransaction.TransactionCompleted += new TransactionCompletedEventHandler(OnTransactionCompleted);
                connectionList.Add(connectionString, connection);
            }

            return connection;
        }
开发者ID:ZhouHengYi,项目名称:HFramework,代码行数:55,代码来源:TransactionScopeConnections.cs

示例2: GetOpenConnection

 private static ConnectionWrapper<DbConnection> GetOpenConnection(string connectionString, IDbFactory factory,
     bool disposeInnerConnection)
 {
     return TransactionScopeConnections.GetOpenConnection(connectionString, () => factory.CreateConnection(), disposeInnerConnection);
 }
开发者ID:jeanmahai,项目名称:PublicTools,代码行数:5,代码来源:DbHelper.cs

示例3: Context

            public Transaction Transaction; // used to keep track of transaction participation.

            #endregion Fields

            #region Constructors

            // to restore lock timeout on ConnectionScope.Dispose().
            public Context(IDbFactory factory, string connectionString)
            {
                this.Factory = factory;
                this.Connection = Factory.CreateConnection();
                this.Connection.ConnectionString = connectionString;
            }
开发者ID:helgihaf,项目名称:Alpha,代码行数:13,代码来源:ConnectionScope.cs


注:本文中的IDbFactory.CreateConnection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。