I'm a newbie with lock / update type question.
I have market-type data that requires constant truncate table & refresh.
If I have code that:
//...fetch some data into dtable1...
// Below: Truncates existing sql table 'table1' & then bulkcopies dtable1 into 'table1'
SqlConnection _con = new SqlConnection();
using (_con = new SqlConnection(servername))
{
SqlCommand sqlTruncate = new SqlCommand("TRUNCATE TABLE table1;", _con);
sqlTruncate.ExecuteNonQuery();
_con.Close();
}
using (var bulkCopy = new SqlBulkCopy(_con.....)
{
bulkCopy.BulkCopyTimeout = 500;
bulkCopy.DestinationTable = "table1";
bulkCopy.WriteToServer(dtable1);
}
How/where do I put locks or something around the Truncate & Bulkcopy so another user can call the 'table1' seamlessly at anytime...so I'd imagine if Truncate AND Bulkcopy are not done yet, user calling data gets prior 'table1' data & user calling data afterwards gets new data without data ever being missing or partial due to in between update?
Thank you!