本文整理汇总了C#中IDalSession.OpenConnection方法的典型用法代码示例。如果您正苦于以下问题:C# IDalSession.OpenConnection方法的具体用法?C# IDalSession.OpenConnection怎么用?C# IDalSession.OpenConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDalSession
的用法示例。
在下文中一共展示了IDalSession.OpenConnection方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InternalDiscoverSpParameterSet
/// <summary>
/// Discover at run time the appropriate set of Parameters for a stored procedure
/// </summary>
/// <param name="session">An IDalSession object</param>
/// <param name="spName">Name of the stored procedure.</param>
/// <param name="includeReturnValueParameter">if set to <c>true</c> [include return value parameter].</param>
/// <returns>The stored procedure parameters.</returns>
private IDataParameter[] InternalDiscoverSpParameterSet(IDalSession session, string spName,
bool includeReturnValueParameter)
{
using (IDbCommand cmd = session.CreateCommand(CommandType.StoredProcedure))
{
cmd.CommandText = spName;
// The session connection object is always created but the connection is not alwys open
// so we try to open it in case.
session.OpenConnection();
DeriveParameters(session.DataSource.DbProvider, cmd);
if (cmd.Parameters.Count > 0) {
IDataParameter firstParameter = (IDataParameter)cmd.Parameters[0];
if (firstParameter.Direction == ParameterDirection.ReturnValue) {
if (!includeReturnValueParameter) {
cmd.Parameters.RemoveAt(0);
}
}
}
IDataParameter[] discoveredParameters = new IDataParameter[cmd.Parameters.Count];
cmd.Parameters.CopyTo(discoveredParameters, 0);
return discoveredParameters;
}
}
示例2: InternalDiscoverSpParameterSet
/// <summary>
/// Discover at run time the appropriate set of Parameters for a stored procedure
/// </summary>
/// <param name="session">An IDalSession object</param>
/// <param name="spName">Name of the stored procedure.</param>
/// <param name="includeReturnValueParameter">if set to <c>true</c> [include return value parameter].</param>
/// <returns>The stored procedure parameters.</returns>
private IDataParameter[] InternalDiscoverSpParameterSet(IDalSession session, string spName,
bool includeReturnValueParameter)
{
#if !dotnet2
// SqlCommandBuilder.DeriveParameters(<command>) does not support transactions.
// If the command is within a transaction, you will get the following error:
// “SqlCommandBuilder Execute requires the command to have a transaction object
// when the connection assigned to the command is in a pending local transaction”
// even when the command object does in fact have a transaction object.
using (IDbConnection connection = session.DataSource.DbProvider.CreateConnection())
{
connection.ConnectionString = session.DataSource.ConnectionString;
connection.Open();
using (IDbCommand cmd = connection.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
#else
using (IDbCommand cmd = session.CreateCommand(CommandType.StoredProcedure))
{
#endif
cmd.CommandText = spName;
// The session connection object is always created but the connection is not alwys open
// so we try to open it in case.
session.OpenConnection();
DeriveParameters(session.DataSource.DbProvider, cmd);
if (cmd.Parameters.Count > 0) {
IDataParameter firstParameter = (IDataParameter)cmd.Parameters[0];
if (firstParameter.Direction == ParameterDirection.ReturnValue) {
if (!includeReturnValueParameter) {
cmd.Parameters.RemoveAt(0);
}
}
}
IDataParameter[] discoveredParameters = new IDataParameter[cmd.Parameters.Count];
cmd.Parameters.CopyTo(discoveredParameters, 0);
return discoveredParameters;
}
#if !dotnet2
}
#endif
}