I'm currently trying to modify a local database using a C# program. I followed this example : https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.commit.aspx
The problem is that the modification is done when the program is running (for instance, if I add a new row, I will see it in my program), but when I stop the program and I check the database, there is no change anymore - the database is exactly the same as before the execution.
I've been working on this issue for several days and haven't found a solution.
Here is an extract of my work:
SqlConnection connectionLocale = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=|DataDirectory|LocalDB.mdf;Integrated Security=True");
SqlCommand command2 = connectionLocale.CreateCommand();
SqlTransaction transaction;
connectionLocale.Open();
transaction = connectionLocale.BeginTransaction();
command2.Connection = connectionLocale;
command2.Transaction = transaction;
try
{
command2.CommandText = "DELETE FROM Chercheur";
command2.ExecuteNonQuery();
transaction.Commit();
Console.WriteLine("commit ok");
}
catch
{
transaction.Rollback();
}
connectionLocale.Close();
I'm using Visual Vtudio 2012 with a .mdf database.
After some research I saw somewhere that the connection (AttachDbFilename=|DataDirectory|LocalDB.mdf)
creates a temporary database and that all the change are done on this temporary database.
How can I affect the original database instead of this temporary database?