Hi, I am attempting to go through a SQL database, find an encrypted string, decrypt it, and then re-encrypt it with a new passphrase. The problem occurs when I try to write to the database while the Reader is still open.
My code roughly looks like:
SqlConnection sc = new SqlConnection("Server=" + dbserver + ";Database=" + db + ";Trusted_Connection=True;MultipleActiveResultSets =True;);
string qs = "SELECT Page, Revision, Content FROM [" + db + "].[dbo].[" + dbtable + "]";
sc.Open();
SqlCommand command = new SqlCommand(qs, sc);
myReader = command.ExecuteReader();
while(myReader.Read())
{
...
qs = "UPDATE [wiki_data_test].[dbo].[PageContent_v2] SET Content=@catContent WHERE Page=@thePage AND Revision=@theRevision";
command = new SqlCommand(qs, sc);
command.ExecuteNonQuery();
...
}
I get the error "Transaction was deadlocked on lock generic waitable...". I tried to create a separate connection just for the writes, but I get an error stating that I cannot connect while the reader is open.