0

So I am having a very weird issue, At first my code to insert items into my access database stopped working, it is a simple code like this:

using (OleDbConnection myCon = new OleDbConnection())
            {
                OleDbCommand cmd = new OleDbCommand()
                {
                    CommandType = CommandType.Text,
                    CommandText = "insert into applicationSalts ([appName],[salt]) values (?,?)"
                };
                cmd.Parameters.AddWithValue("@appName", appName);
                cmd.Parameters.AddWithValue("@salt", salt);
                myCon.ConnectionString = publicDbConnectionString;
                cmd.Connection = myCon;
                myCon.Open();
                int result = cmd.ExecuteNonQuery();
                myCon.Close();
            }

So it is very straight forward, inserting those values and I checked that result = 1 (query finished successfully).

Now it gets a bit weird, The database happens to not show any new values. Which is weird, Then I tried renaming the database and then all those records appear later! I tried using the database from another location (I was using it from C:/databaseName then now used it from D:/databaseName) then it worked. I moved the database file that worked back into C, then suddenly the records that appeared before disappeared.

Much weirder is that at the beginning one of the tables in the same database used to be working with an ideantical call as the one prior to this. But this one didnt! Then when I was trying to find the issue that one also stopped working..

Also after I manually changed some records when it was working through ms access it later ignored the changes..

I am slowly going insane as I am not really understanding what is going on, This is using access 2000 file format.

Edit: After further experimentation it is still getting weirder for me, While the file is called onlineDb.mdb it had a single record, deleting that made it disappear, Now renaming it to onDb.mdb made that record come back, adding other records that were missing. Then renaming to onlineDB.mdb again made all records disappear.

Zaid Al Shattle
  • 313
  • 2
  • 13
  • 2
    It sounds like you're looking a a different database than `myCon.DataSource`. – Dour High Arch Dec 18 '19 at 18:38
  • "Now it gets a bit weird, The database happens to not show any new values. Which is weird, Then I tried renaming the database and then all those records appear later!" Sounds like the Data was not yet written or the view did not properly Update while the file was in use. – Christopher Dec 18 '19 at 18:38
  • 1
    You are either looking at the wrong database **or** it could be that you included the data file in the project and with each execution (ctl+f5) from Visual Studio you are overwriting the database file. – Igor Dec 18 '19 at 18:39
  • It's weird because if I rename the database back the records disappear again – Zaid Al Shattle Dec 18 '19 at 18:41
  • Also I am certainly writing the correct file. All the commands end up visible at some point. – Zaid Al Shattle Dec 18 '19 at 18:42

0 Answers0