using System;
using System.Xml;
using System.Xml.Serialization;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Diagnostics;
using System.Runtime;
using System.Runtime.Serialization;
using Tdo;
using Tdo.Common;
using Tdo.Common.Entities;
using Tdo.Common.Entities.Tables;
using Tdo.Common.Entities.Views;
using Tdo.Common.Helper;
using Tdo.Common.TdoSqlExpressionDom;
using Tdo.Common.TdoTypes;
namespace Tdo.Common.Programmability{
/// <summary>
/// Base class for all Stored Procedures
/// </summary>
[Serializable]
[CLSCompliant(true)]
[Browsable(false)]
public class TdoStoredProcedureBase : ITdoStoredProcedure
{
#region Fields
/// <summary>
/// Stored Procedure Name
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
protected string procedurename;
/// <summary>
/// Stored Procedure Schema Name
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
protected string pSchemaName;
/// <summary>
/// TdoHelper reference to share common resources
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields"), NonSerialized()]
protected ITdoHelper pTdoHelper;
/// <summary>
/// Stored Procedure SqlParamaters Array
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")]
[NonSerialized()]
protected SqlParameter[] pParameters;
#endregion Fields
#region Constructors
/// <summary>
/// TdoStoredProcedureBase default constructor.
/// </summary>
public TdoStoredProcedureBase()
{
}
#endregion Constructors
#region Properties
/// <summary>
/// Get TdoHelper reference to share common resources
/// </summary>
[XmlIgnore()]
public ITdoHelper TdoHelper
{
get
{
return this.pTdoHelper;
}
}
/// <summary>
/// Stored Procedure Schema Name
/// </summary>
public string SchemaName
{
get
{
return this.pSchemaName;
}
}
/// <summary>
/// Stored Procedure Name
/// </summary>
public string Name
{
get
{
return this.procedurename;
}
}
/// <summary>
/// Get Full Name ([schema].[name])
/// </summary>
[Browsable(false)]
public string FullName
{
get
{
return String.Concat(this.pSchemaName, ".", this.procedurename);
}
}
#endregion Properties
#region Methods
/// <summary>
/// Assign SqlParameter values.
/// </summary>
/// <param name="parameters">Array of INullable parameters like (SqlString, SqlInt32, ...)</param>
protected virtual void AssignParameterValues(params INullable[] parameters)
{
int count = 0;
for (int i = 0; i < this.pParameters.Length; i++)
{
if (this.pParameters[i].Direction==ParameterDirection.Input || this.pParameters[i].Direction==ParameterDirection.InputOutput)
if (parameters[count] != null)
{
this.pParameters[i].Value = parameters[count];
count++;
}
}
}
/// <summary>
/// Execute Stored Procedure and returns a DataTable
/// </summary>
/// <returns>A System.Data.DataSet to fill with Stored Procedure result set.</returns>
public virtual DataTable FillDataTable()
{
return (DataTable)this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.DataTable);
}
/// <summary>
/// Execute Stored Procedure and returns a DataSet
/// </summary>
/// <returns>A System.Data.DataSet to fill with Stored Procedure result set.</returns>
public virtual DataSet FillDataSet()
{
return (DataSet)this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.DataSet);
}
/// <summary>
/// Executes Stored Procedure against the connection and returns the number of rows affected.
/// </summary>
/// <returns>The number of rows affected.</returns>
public virtual int ExecuteNonQuery()
{
return (int)this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.NonQuery);
}
/// <summary>
/// Execute Stored Procedure and builds a System.Data.SqlClient.SqlDataReader.
/// </summary>
/// <param name="commandBehavior">One of the System.Data.CommandBehavior values.</param>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>A System.Data.SqlClient.SqlDataReader object.</returns>
public virtual SqlDataReader ExecuteReader(CommandBehavior commandBehavior, out SqlParameterCollection sqlOutputParameterCollection)
{
return (SqlDataReader)this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.Reader, commandBehavior, out sqlOutputParameterCollection);
}
/// <summary>
/// Execute Stored Procedure and builds a System.Data.SqlClient.SqlDataReader.
/// </summary>
/// <param name="commandBehavior">One of the System.Data.CommandBehavior values.</param>
/// <returns>A System.Data.SqlClient.SqlDataReader object.</returns>
public virtual SqlDataReader ExecuteReader(CommandBehavior commandBehavior)
{
SqlParameterCollection sqlOutputParameterCollection;
return (SqlDataReader)this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.Reader, commandBehavior, out sqlOutputParameterCollection);
}
/// <summary>
/// Execute Stored Procedure and builds a System.Data.SqlClient.SqlDataReader.
/// </summary>
/// <returns>A System.Data.SqlClient.SqlDataReader object.</returns>
public virtual SqlDataReader ExecuteReader()
{
SqlParameterCollection sqlOutputParameterCollection;
return (SqlDataReader)this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.Reader, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Executes Stored Procedure, and returns the first column of the first row in the result set returned by Stored Procedure. Extra columns or rows are ignored.
/// </summary>
/// <returns>The first column of the first row in the result set, or a null reference if the result set is empty.</returns>
public virtual object ExecuteScalar()
{
return this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.Scalar);
}
/// <summary>
/// Execute Stored Procedure and builds a System.Xml.XmlReader.
/// </summary>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>A System.Xml.XmlReader object.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")]
public virtual XmlReader ExecuteXmlReader(out SqlParameterCollection sqlOutputParameterCollection)
{
return this.ExecuteSyncStoredProcedure(out sqlOutputParameterCollection);
}
/// <summary>
/// Execute Stored Procedure and builds a System.Xml.XmlReader.
/// </summary>
/// <returns>A System.Xml.XmlReader object.</returns>
public virtual XmlReader ExecuteXmlReader()
{
return (XmlReader)this.ExecuteSyncStoredProcedure(StoredProcedureSyncResultType.XmlReader);
}
/// <summary>
/// Clear all SqlParameter Value.
/// </summary>
public void ClearParameterValues()
{
for (int i = 0; i < this.pParameters.Length; i++)
{
{
this.pParameters[i].Value = null;
}
}
}
/// <summary>
/// Re-assigns output parameter values after Stored Procedure execution.
/// </summary>
/// <param name="sqlCommand">SqlCommand with SqlParamater Collection.</param>
public void AssignOutputParameterValues(SqlCommand sqlCommand)
{
this.AssignOutputParameterValues(sqlCommand.Parameters);
}
/// <summary>
/// Re-assigns output parameter values after Stored Procedure execution.
/// </summary>
/// <param name="sqlParameterCollection">SqlParameterCollection with values.</param>
public void AssignOutputParameterValues(SqlParameterCollection sqlParameterCollection)
{
for (int i = 0; i < this.pParameters.Length; i++)
{
if (this.pParameters[i].Direction == ParameterDirection.InputOutput
||
this.pParameters[i].Direction == ParameterDirection.Output
||
this.pParameters[i].Direction == ParameterDirection.ReturnValue)
{
this.pParameters[i].Value = sqlParameterCollection[this.pParameters[i].ParameterName].Value;
}
}
}
internal XmlReader ExecuteSyncStoredProcedure(out SqlParameterCollection sqlOutputParameterCollection)
{
this.TdoHelper.PrepareAutomaticConnection();
this.TdoHelper.PrepareAutomaticTransaction();
SqlCommand sqlCommand = this.TdoHelper.CreateCommand(this.FullName, CommandType.StoredProcedure, this.pParameters);
XmlReader xrResults = sqlCommand.ExecuteXmlReader();
sqlOutputParameterCollection = sqlCommand.Parameters;
return xrResults;
}
internal object ExecuteSyncStoredProcedure(StoredProcedureSyncResultType storedProcedureResultType)
{
SqlParameterCollection sqlOutputParameterCollection;
return this.ExecuteSyncStoredProcedure(storedProcedureResultType, CommandBehavior.Default, out sqlOutputParameterCollection);
}
internal object ExecuteSyncStoredProcedure(StoredProcedureSyncResultType storedProcedureResultType, CommandBehavior commandBehavior, out SqlParameterCollection sqlOutputParameterCollection)
{
this.TdoHelper.PrepareAutomaticConnection();
this.TdoHelper.PrepareAutomaticTransaction();
SqlCommand sqlCommand = this.TdoHelper.CreateCommand(this.FullName, CommandType.StoredProcedure, this.pParameters);
sqlCommand.StatementCompleted += new StatementCompletedEventHandler(this.internalTdoCommandStatementCompleted);
sqlCommand.StatementCompleted += new StatementCompletedEventHandler(this.TdoHelper.internalStatementCompletedEventHandler);
sqlOutputParameterCollection = sqlCommand.Parameters;
//SYNC
switch (storedProcedureResultType)
{
case StoredProcedureSyncResultType.DataSet:
DataSet dsResult = new DataSet(this.procedurename);
dsResult.Locale = System.Globalization.CultureInfo.InvariantCulture;
SqlDataAdapter dsda = new SqlDataAdapter();
dsda.SelectCommand = sqlCommand;
dsda.Fill(dsResult);
this.AssignOutputParameterValues(sqlCommand);
this.TdoHelper.UnPrepareAutomaticConnection();
this.TdoHelper.UnPrepareAutomaticTransaction();
return dsResult;
case StoredProcedureSyncResultType.DataTable:
DataTable dtResult = new DataTable(this.procedurename);
dtResult.Locale = System.Globalization.CultureInfo.InvariantCulture;
SqlDataAdapter dtda = new SqlDataAdapter();
dtda.SelectCommand = sqlCommand;
dtda.Fill(dtResult);
this.AssignOutputParameterValues(sqlCommand);
this.TdoHelper.UnPrepareAutomaticConnection();
this.TdoHelper.UnPrepareAutomaticTransaction();
return dtResult;
case StoredProcedureSyncResultType.NonQuery:
int intResult = sqlCommand.ExecuteNonQuery();
this.AssignOutputParameterValues(sqlCommand);
this.TdoHelper.UnPrepareAutomaticConnection();
this.TdoHelper.UnPrepareAutomaticTransaction();
return intResult;
case StoredProcedureSyncResultType.Reader:
SqlDataReader drResult = sqlCommand.ExecuteReader(commandBehavior);
return drResult;
case StoredProcedureSyncResultType.XmlReader:
XmlReader xResults = sqlCommand.ExecuteXmlReader();
return xResults;
case StoredProcedureSyncResultType.Scalar:
object scalarResult = sqlCommand.ExecuteScalar();
this.AssignOutputParameterValues(sqlCommand);
this.TdoHelper.UnPrepareAutomaticConnection();
this.TdoHelper.UnPrepareAutomaticTransaction();
return scalarResult;
default:
throw new ArgumentException("Unsupported type (" + storedProcedureResultType.ToString() + ")", "storedProcedureResultType");
}
}
private void internalAsyncCommandTerminated(IAsyncResult asyncResult)
{
TdoStateObject tdoStateObject = asyncResult.AsyncState as TdoStateObject;
if (tdoStateObject == null)
throw new InvalidProgramException("Tdo Internal Error in internalAsyncCommandTerminated. Cannot retrieve TdoStateObject. Please report this error at Tdo Staff.");
if (tdoStateObject.callBack != null)
{
TdoAsyncResult tdoAsyncResult = new TdoAsyncResult();
tdoAsyncResult.pAsyncState = tdoStateObject.StateObject;
tdoAsyncResult.pAsyncWaitHandle = asyncResult.AsyncWaitHandle;
tdoAsyncResult.pCompletedSynchronously = asyncResult.CompletedSynchronously;
tdoAsyncResult.pIsCompleted = asyncResult.IsCompleted;
tdoStateObject.callBack(tdoAsyncResult);
}
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider")]
private object internalEndAsyncCommand(IAsyncResult asyncResult)
{
if (asyncResult == null)
throw new ArgumentNullException("asyncResult", "value cannot be null");
TdoStateObject tdoStateObject = asyncResult.AsyncState as TdoStateObject;
if (tdoStateObject == null)
throw new InvalidCastException("asyncResult is not the same returned object from Begin method.");
string methodName = tdoStateObject.MethodName;
Guid key = tdoStateObject.AsyncCommandUniqueIdentifier;
if (!((ITdoHelper)this.TdoHelper).SqlCommandAsyncStore.Contains(key))
throw new InvalidOperationException("Begin_method must be invoked first of End_method or End_method was invoked more then once.");
SqlCommand comm = ((ITdoHelper)this.TdoHelper).SqlCommandAsyncStore[key] as SqlCommand;
if (comm == null)
throw new InvalidCastException(String.Format("asyncResult is not the same returned object from Begin_method.", methodName));
try
{
switch (methodName)
{
case "NonQuery":
int intResult = comm.EndExecuteNonQuery(asyncResult);
this.AssignOutputParameterValues(comm);
return intResult;
case "XmlReader":
return comm.EndExecuteXmlReader(asyncResult);
case "Reader":
return comm.EndExecuteReader(asyncResult);
default:
throw new ArgumentException(String.Format("Invalid async result type name ({0})", methodName));
}
}
finally
{
((ITdoHelper)this.TdoHelper).SqlCommandAsyncStore.Remove(key);
}
}
/// <summary>
/// Finishes asynchronous execution of a stored procedure and return specific result.
/// </summary>
/// <param name="asyncResult">The System.IAsyncResult returned by the call to Begin_pStored_procedure_name.</param>
/// <returns>object (System.Data.SqlDataReader/System.Int32/System.Xml.XmlReader)that can be used to retrieve the requested results.</returns>
protected object EndAsyncStoredProcedure(IAsyncResult asyncResult)
{
return ((SqlDataReader)this.internalEndAsyncCommand(asyncResult));
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <param name="commandBehavior">One of the System.Data.CommandBehavior values.</param>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
protected IAsyncResult ExecuteAsyncStoredProcedure(AsyncCallback callBack, object stateObject, CommandBehavior commandBehavior, out SqlParameterCollection sqlOutputParameterCollection)
{
this.TdoHelper.PrepareAutomaticConnection();
this.TdoHelper.PrepareAutomaticTransaction();
SqlCommand sqlCommand = this.TdoHelper.CreateCommand(this.FullName, CommandType.StoredProcedure, this.pParameters);
sqlCommand.StatementCompleted += new StatementCompletedEventHandler(this.internalTdoCommandStatementCompleted);
sqlCommand.StatementCompleted += new StatementCompletedEventHandler(this.TdoHelper.internalStatementCompletedEventHandler);
AsyncCallback tdoAsyncCallback = new AsyncCallback(this.internalAsyncCommandTerminated);
TdoStateObject tdoStateObject = new TdoStateObject(callBack, stateObject, StoredProcedureAsyncResultType.Reader.ToString());
//Add Command to SqlCommandAsyncStore
((ITdoHelper)(this.TdoHelper)).SqlCommandAsyncStore.Add(tdoStateObject.AsyncCommandUniqueIdentifier, sqlCommand);
//ASYNC
IAsyncResult iar = sqlCommand.BeginExecuteReader(tdoAsyncCallback, tdoStateObject, commandBehavior);
sqlOutputParameterCollection = sqlCommand.Parameters;
return iar;
}
internal IAsyncResult ExecuteAsyncStoredProcedure(AsyncCallback callBack, object stateObject, StoredProcedureAsyncResultType storedProcedureResultType)
{
this.TdoHelper.PrepareAutomaticConnection();
this.TdoHelper.PrepareAutomaticTransaction();
SqlCommand sqlCommand = this.TdoHelper.CreateCommand(this.FullName, CommandType.StoredProcedure, this.pParameters);
sqlCommand.StatementCompleted += new StatementCompletedEventHandler(this.internalTdoCommandStatementCompleted);
sqlCommand.StatementCompleted += new StatementCompletedEventHandler(this.TdoHelper.internalStatementCompletedEventHandler);
AsyncCallback tdoAsyncCallback = new AsyncCallback(this.internalAsyncCommandTerminated);
TdoStateObject tdoStateObject = new TdoStateObject(callBack, stateObject, storedProcedureResultType.ToString());
//Add Command to SqlCommandAsyncStore
((ITdoHelper)(this.TdoHelper)).SqlCommandAsyncStore.Add(tdoStateObject.AsyncCommandUniqueIdentifier, sqlCommand);
//ASYNC
switch (storedProcedureResultType)
{
case StoredProcedureAsyncResultType.NonQuery:
return sqlCommand.BeginExecuteNonQuery(tdoAsyncCallback, tdoStateObject);
case StoredProcedureAsyncResultType.Reader:
return sqlCommand.BeginExecuteReader(tdoAsyncCallback, tdoStateObject, CommandBehavior.Default);
case StoredProcedureAsyncResultType.XmlReader:
return sqlCommand.BeginExecuteXmlReader(tdoAsyncCallback, tdoStateObject);
default:
throw new ArgumentException(String.Format("Invalid async result type name ({0})", storedProcedureResultType.ToString()));
}
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <param name="commandBehavior">One of the System.Data.CommandBehavior values.</param>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteReader(AsyncCallback callBack, object stateObject, CommandBehavior commandBehavior, out SqlParameterCollection sqlOutputParameterCollection)
{
return this.ExecuteAsyncStoredProcedure(callBack, stateObject, commandBehavior, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteReader(AsyncCallback callBack, object stateObject, out SqlParameterCollection sqlOutputParameterCollection)
{
return this.ExecuteAsyncStoredProcedure(callBack, stateObject, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <param name="commandBehavior">One of the System.Data.CommandBehavior values.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteReader(AsyncCallback callBack, object stateObject, CommandBehavior commandBehavior)
{
SqlParameterCollection sqlOutputParameterCollection;
return this.ExecuteAsyncStoredProcedure(callBack, stateObject, commandBehavior, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteReader(AsyncCallback callBack, object stateObject)
{
SqlParameterCollection sqlOutputParameterCollection;
return this.ExecuteAsyncStoredProcedure(callBack, stateObject, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="commandBehavior">One of the System.Data.CommandBehavior values.</param>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteReader(CommandBehavior commandBehavior, out SqlParameterCollection sqlOutputParameterCollection)
{
return this.ExecuteAsyncStoredProcedure(null, null, commandBehavior, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="commandBehavior">One of the System.Data.CommandBehavior values.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteReader(CommandBehavior commandBehavior)
{
SqlParameterCollection sqlOutputParameterCollection;
return this.ExecuteAsyncStoredProcedure(null, null, commandBehavior, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")]
public IAsyncResult BeginExecuteReader(out SqlParameterCollection sqlOutputParameterCollection)
{
return this.ExecuteAsyncStoredProcedure(null, null, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteReader()
{
SqlParameterCollection sqlOutputParameterCollection;
return this.ExecuteAsyncStoredProcedure(null, null, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Finishes asynchronous execution of Stored Procedure, returning the requested System.Data.SqlClient.SqlDataReader.
/// </summary>
/// <param name="asyncResult">The System.IAsyncResult returned by the call to BeginExecuteReader.</param>
/// <returns>A System.Data.SqlClient.SqlDataReader object that can be used to retrieve the requested rows.</returns>
public SqlDataReader EndExecuteReader(IAsyncResult asyncResult)
{
return (SqlDataReader)this.EndAsyncStoredProcedure(asyncResult);
}
/// <summary>
/// Finishes asynchronous execution of Stored Procedure, returning the requested System.Xml.XmlReader.
/// </summary>
/// <param name="asyncResult">The System.IAsyncResult returned by the call to BeginExecuteXmlReader.</param>
/// <returns>A System.Xml.XmlReader object that can be used to retrieve the requested rows.</returns>
public XmlReader EndExecuteXmlReader(IAsyncResult asyncResult)
{
return (XmlReader)this.EndAsyncStoredProcedure(asyncResult);
}
/// <summary>
/// Finishes asynchronous execution of Stored Procedure.
/// </summary>
/// <param name="asyncResult">The System.IAsyncResult returned by the call to BeginExecuteNonQuery.</param>
/// <returns>The number of rows affected.</returns>
public int EndExecuteNonQuery(IAsyncResult asyncResult)
{
return (int)this.EndAsyncStoredProcedure(asyncResult);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteXmlReader(AsyncCallback callBack, object stateObject, out SqlParameterCollection sqlOutputParameterCollection)
{
return this.ExecuteAsyncStoredProcedure(callBack, stateObject, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteNonQuery(AsyncCallback callBack, object stateObject)
{
return this.ExecuteAsyncStoredProcedure(callBack, stateObject, StoredProcedureAsyncResultType.NonQuery);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteNonQuery()
{
return this.ExecuteAsyncStoredProcedure(null, null, StoredProcedureAsyncResultType.NonQuery);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="callBack">An System.AsyncCallback delegate that will be invoked when the command's execution has completed. Pass null (Nothing in Visual Basic) to indicate that no callBack is needed.</param>
/// <param name="stateObject">A user-defined state object that will be passed to the callBack procedure. Retrieve this object from within the callBack procedure using the System.IAsyncResult.AsyncState property.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteXmlReader(AsyncCallback callBack, object stateObject)
{
SqlParameterCollection sqlOutputParameterCollection;
return this.ExecuteAsyncStoredProcedure(callBack, stateObject, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
public IAsyncResult BeginExecuteXmlReader()
{
SqlParameterCollection sqlOutputParameterCollection;
return this.ExecuteAsyncStoredProcedure(null, null, CommandBehavior.Default, out sqlOutputParameterCollection);
}
/// <summary>
/// Initiates the asynchronous execution of stored procedure described, and retrieves one or more result sets from the server.
/// </summary>
/// <param name="sqlOutputParameterCollection">SqlParameterCollection with output parameters.</param>
/// <returns>An System.IAsyncResult that can be used to poll and/or wait for results; this value is also needed when invoking EndExecuteXXXX() methods.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters")]
public IAsyncResult BeginExecuteXmlReader(out SqlParameterCollection sqlOutputParameterCollection)
{
return this.ExecuteAsyncStoredProcedure(null, null, CommandBehavior.Default, out sqlOutputParameterCollection);
}
#endregion Methods
#region Events
/// <summary>
/// Occurs after a command is executed against the data source.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2235:MarkAllNonSerializableFields"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2235:MarkAllNonSerializableFields")]
public event StatementCompletedEventHandler StatementCompleted;
internal void internalTdoCommandStatementCompleted(object sender, StatementCompletedEventArgs e)
{
if (this.StatementCompleted != null)
this.StatementCompleted(sender, e);
}
#endregion Events
}
}
|