Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi,

I have a method which does sql database backup and restore. since this can be time consuming activity

so i am collecting relevant data in a dataTable and then trying to pass those as parameter in the method

C#
Parallel.ForEach(dtRestoreQueue.AsEnumerable(), drow =>
{
    PerformDBBackup(drow["Source backup Directory"].ToString(), drow["Source Server Database"].ToString(), drow["Destination backup Directory"].ToString(), drow["Source Server Instance"].ToString(), drow["Destination Server Instance"].ToString(), Convert.ToBoolean(drow["Source Integrated Security"].ToString()), drow["Source User Name"].ToString(), drow["Source Password"].ToString(), drow["Destination Data Directory"].ToString(), drow["Destination Log Directory"].ToString(), drow["Restore Database Name"].ToString());

});


but this is not working and i am getting wierd error like file is in use like that

but whenever i am doing the same with for loop the code is working fine as expected

could you please let me know how to call the this method in parallel any other way to do this.
Posted
Updated 25-Oct-14 17:41pm
v2
Comments
Sergey Alexandrovich Kryukov 25-Oct-14 23:29pm    
The question does not make sense because there is no such thing as "instance of a method". Methods don't have instances.
—SA
DamithSL 26-Oct-14 0:05am    
Are you share the same database connection with each parallel execution?

1 solution

Parallelizing it may not help: the best solution is to use "proper" backup methods, and if necessary call them in a BackgroundWorker.
Have a look at this: Backing up an SQL Database in C#[^] - it may help.
 
Share this answer
 
Comments
[no name] 26-Oct-14 7:31am    
Thanks for the link ;) 5
OriginalGriff 26-Oct-14 8:03am    
You're welcome!

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