I have to update a table containing millions of records. Now I am storing the id's of all the records to be updated in a List. The query is generated pragmatically as follows :
string queryPart="";
foreach (int id in transactionsToUpdate.ToList())
{
queryPart+="TransactionID="+id;
queryPart+=" OR ";
}
queryPart += "1=0";
string query = @"UPDATE dbo.OutgoingQueue SET Status='C' WHERE "+queryPart;
Currently even with 100,000 values in the list, there are two problems coming up. Firstly, the code above takes a long time to execute ( the query formation part ). And secondly, when I execute the query on DB it gives Timeout Expired exception. Is there is a better way to achieve what I want ?
UPDATE : The first problem of query taking a long time to form has been solved by using stringbuilder. But the second problem still remains. If I increase the timeout, then I get sql out of resource exception.