本文整理汇总了C#中IDbConnection.EnsureOpen方法的典型用法代码示例。如果您正苦于以下问题:C# IDbConnection.EnsureOpen方法的具体用法?C# IDbConnection.EnsureOpen怎么用?C# IDbConnection.EnsureOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDbConnection
的用法示例。
在下文中一共展示了IDbConnection.EnsureOpen方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildSchema
public void BuildSchema(IDbConnection conn)
{
conn.EnsureOpen();
foreach (string statement in createSql)
conn.Execute(statement);
}
示例2: UnitOfWork
public UnitOfWork(IDbConnection connection)
{
if (connection == null)
throw new ArgumentNullException("connection");
_connection = connection;
connection.EnsureOpen();
_transaction = connection.BeginTransaction();
}
示例3: ExecuteReader
/// <summary>
/// Sorguyu belirtilen bağlantı üzerinde çalıştırır ve bir IDataReader nesnesi döndürür.</summary>
/// <param name="connection">
/// Sorgunun çalıştırılacağı bağlantı. Açık değilse otomatik olarak açılır.</param>
/// <param name="commandText">
/// Çalıştırılacak SQL sorgusu.</param>
/// <param name="param">
/// Parameters (optional).</param>
/// <returns>
/// Sorgunun çalıştırılması sonucu elde edilen IDataReader nesnesi.</returns>
public static IDataReader ExecuteReader(IDbConnection connection, string commandText,
IDictionary<string, object> param)
{
if (connection == null)
throw new ArgumentNullException("connection");
connection.EnsureOpen();
try
{
//using (new Tracer(commandText))
{
IDbCommand command = NewCommand(connection, commandText, param);
try
{
if (Log.IsDebugEnabled)
LogCommand("ExecuteReader", command);
var result = command.ExecuteReader();
if (Log.IsDebugEnabled)
Log.Debug("END - ExecuteReader");
return result;
}
catch (System.Data.SqlClient.SqlException ex)
{
if (CheckConnectionPoolException(connection, ex))
return command.ExecuteReader();
else
throw;
}
}
}
catch (Exception ex)
{
ex.SetData("sql_command_text", commandText);
throw;
}
}
示例4: Clear
public void Clear(IDbConnection conn)
{
conn.EnsureOpen();
using (var tx = conn.BeginTransaction())
{
foreach (string statement in clearSql)
conn.Execute(statement, transaction: tx);
tx.Commit();
}
}