Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am calling a store procedure and fetching the dataset. But once i complete the execution i need to clear the temp tables that are created while executing the stroce proc. But i want to do this operation in a Asyncronous method, which means i will fetch the results and return the dataset and paralelly try to drop the temp tables that are created while execution, so that i can reduce the time and increase the response time for the DB call.
ThreadPool and BackgroundWorker are the functionlities that i used for Async call. When I call the method in Async way the transaction object which was created earlier was no more available and now its trying to create a new thread to complete the process. And the temp tables that are created earlier were not present in this thread hence i am getting an exception.
This is the issue i am facing as of now. Can anybody help me out to resolve this issue.

Rob here is the peiece of code which you were asking
storedProcedureName- string
tempTable- string[] these two are the input parameters for this method
dataSet- return value from this method

Database database;//Create Database with help of connection string
DbConnection connection = database.CreateConnection();
connection.Open();
DbTransaction transaction = connection.BeginTransaction();

using (DbCommand dbCommand = database.GetStoredProcCommand(storedProcedureName))
{
//Loading DataSet after passing inout parameters.
database.LoadDataSet(dbCommand, dataSet, dataTable);
}
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += (o, t) =>
{
if (tempTable != null && tempTable.Length > 0)
{
foreach (string dropCommand in tempTable)
{
try
{
//Call to drop temp table
database.ExecuteNonQuery(transaction, CommandType.Text, dropCommand);
}
catch (Exception ex)
{
MessageBox.Show(dropCommand + "&& " + ex);
}
}
}
transaction.Commit();
connection.Close();
};
bw.RunWorkerAsync();
Posted
Updated 27-Jul-14 21:57pm
v2
Comments
Rob Philpott 25-Jul-14 9:57am    
Can you expand a bit - the stored procedure creates some temporary tables, executes a query, and then does it drop the temporary table. Is the transaction in the scope of the stored proc or are you creating it ADO.NET?
Member 9990662 28-Jul-14 4:01am    
Hi Rob, I am executing the query but ineed to manually drop the tables the store proc itself will not drop it. I have created the transaction in ADO.NET only with DBTransaction (I am using DB2 databse).
As per your suggestion i have updated the question with Code, can you just go through the code and suggest me to resolve this issue ASAP

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900