I am using SMO to script out my objects from Sql server database using .Net code. But as of now I am going through a sequential loop.
foreach(var table in TableCollection)
{
var stringCollection=table.Script();
}
It is working fine. But when I convert the same loop to a Parallel.ForEach
loop like:
Parallel.ForEach(TableCollection,table=>
{
var stringCollection=table.Script();
});
It fails to script. Is there anybody who has used the same kind of approach or any other approach to script out objects from Sql server in parallel?
UPDATE :
I haven't been able to work out Parallel LOOP as of now but I have used below mentioned code :
server.SetDefaultInitFields(true);
It improves performance up-to some extent.