[sqlite] ChangePassword method problem
Hi, I just want to make sure that I am not doing something wrong, but I have a simple application that opens an encrypted database using it's password and calls the ChangePassword method on it (as shown on numerous posts in this forum). After the password is changed when I try to open the database again, I get the "File is not..." error, as though you are opening an encrypted database with the wrong password. I have tried different combinations of ChangePassword, including setting the password to null and then setting a password again but the same issue keeps occurring. I am using C# with sqlite-netFx40-binary-bundle-Win32-2010-1.0.76.0, and NUnit for my tests. My development machine is Windows 7 64-bit, but I am compiling a 32-bit application (everything else with System.Data.SQLite works perfectly in my application except this). Any help would be greatly appreciated, thanks. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Farhan Husain wrote: > > After the password is changed when I try to open the database again, I get the > "File is not..." error, as though you are opening an encrypted database with > the wrong password. > Before you tried to open the database again, did you call the SetPassword method on that connection object (or supply the password as plain-text in the connection string)? -- Joe Mistachkin ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Yup. Here's what I have tried doing: 1) Created a new encrypted database with a password2) After opening the connection, use ChangePassword to change the password, then close it3) Open the connection again using the new password I have tried opening all encrypted databases using both the SetPassword method and the password property in the connection string. No matter what combination I use, after the password is changed using ChangePassword method, the database becomes unreadable using the updated or previous password. I've even tried creating an unencrypted database, then setting a password, then changing it, and creating an encrypted database, then removing the password using ChangePassword. Basically anytime ChangePassword is called the database becomes unreadable. Everything else seems to work perfectly fine. I have tried this on several machines (32bit, 64bit, winxp and win7) just to make sure it had nothing to do with the development machine. > From: sql...@mistachkin.com > To: sqlite-users@sqlite.org > Date: Sat, 22 Oct 2011 19:38:58 -0700 > Subject: Re: [sqlite] ChangePassword method problem > > > Farhan Husain wrote: > > > > After the password is changed when I try to open the database again, I get > the > > "File is not..." error, as though you are opening an encrypted database > with > > the wrong password. > > > > Before you tried to open the database again, did you call the SetPassword > method > on that connection object (or supply the password as plain-text in the > connection > string)? > > -- > Joe Mistachkin > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Farhan Husain wrote: > > I have tried opening all encrypted databases using both the SetPassword method > and the password property in the connection string. No matter what combination I > use, after the password is changed using ChangePassword method, the database > becomes unreadable using the updated or previous password. > I've added some more unit tests to the test suite to verify that this feature works as documented and I'm not seeing any issues. Could you post some simplified C# code that demonstrates the behavior you are seeing? -- Joe Mistachkin ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Sure. connectionString is in the "Data Source=xxx;Password=xxx;" format. Here is a sample method that uses the connection string: public int ExecuteNonQuery(string query){ using(SQLiteConnection conn = new SQLiteConnection(connectionString)) {conn.Open();using(SQLiteCommand cmd = new SQLiteCommand(query, conn)){int result = cmd.ExecuteNonQuery();conn.Close(); return result;}}} It works perfectly when the database is initially created or subsequently accessed. Here is the changepassword code: // DOES NOT WORKpublic bool ChangePassword(string newPassword){ try{using (SQLiteConnection conn = new SQLiteConnection(connectionString)){ conn.Open();conn.ChangePassword(newPassword); // Also tried null as String then another call to changepassword conn.Close();}}catch (SQLiteException e){exceptionMessage = e.Message; return false;} return true;} When a query is executed, it always uses current password. After the above code is called, neither the old or the new password work. One temporary solution I have found is that I just create a new database with the desired password and transfer all the contents from the old database to it. After that, i simply delete the original database. The problem with this process is that the database file creation date changes every time the password changes. Again, it is possible that I am still doing something wrong with the coding but at this point I am not sure. > From: sql...@mistachkin.com > To: sqlite-users@sqlite.org > Date: Sat, 22 Oct 2011 20:39:09 -0700 > Subject: Re: [sqlite] ChangePassword method problem > > > Farhan Husain wrote: > > > > I have tried opening all encrypted databases using both the SetPassword > method > > and the password property in the connection string. No matter what > combination I > > use, after the password is changed using ChangePassword method, the > database > > becomes unreadable using the updated or previous password. > > > > I've added some more unit tests to the test suite to verify that this > feature works > as documented and I'm not seeing any issues. Could you post some simplified > C# code > that demonstrates the behavior you are seeing? > > -- > Joe Mistachkin > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
One thing that could be a potential issue here is that all connections must be closed prior to changing the password on the database [except the connection used for the ChangePassword method call itself]. -- Joe Mistachkin ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Aah, ok. So, for all the methods that act on the database I should explicitly add conn.Close() within the using conn scope? > From: sql...@mistachkin.com > To: sqlite-users@sqlite.org > Date: Sat, 22 Oct 2011 22:04:33 -0700 > Subject: Re: [sqlite] ChangePassword method problem > > > One thing that could be a potential issue here is that all connections must > be closed > prior to changing the password on the database [except the connection used > for the > ChangePassword method call itself]. > > -- > Joe Mistachkin > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Farhan Husain wrote: > > Aah, ok. So, for all the methods that act on the database I should explicitly add > conn.Close() within the using conn scope? > Well, I'm not familiar with your specific project; however, that does not sound like a bad idea. -- Joe Mistachkin ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
So, I was just wondering how you would deal with multiple processes accessing the database. You can't guarantee that all would be closing the connection properly. It would seem that if all connections needed to be closed before a proper changepassword call can take place, then the chances of database corruption would increase in a multi-process/multi-access environment. I haven't adjusted the code based on your reply yet, but as soon as I do I will post the results. Thanks! > From: sql...@mistachkin.com > To: sqlite-users@sqlite.org > Date: Sat, 22 Oct 2011 23:33:05 -0700 > Subject: Re: [sqlite] ChangePassword method problem > > > Farhan Husain wrote: > > > > Aah, ok. So, for all the methods that act on the database I should > explicitly add > > conn.Close() within the using conn scope? > > > > Well, I'm not familiar with your specific project; however, that does not > sound like > a bad idea. > > -- > Joe Mistachkin > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
On 24 Oct 2011, at 4:42am, Farhan Husain wrote: > So, I was just wondering how you would deal with multiple processes accessing > the database. You can't guarantee that all would be closing the connection > properly. It would seem that if all connections needed to be closed before a > proper changepassword call can take place, then the chances of database > corruption would increase in a multi-process/multi-access environment. How did you expect it to work when you designed the system ? After all, changing the password to a database when lots of other processes are reading it would naturally cause problems for those processes. They would all suddenly start generating errors because they'd be unable to access their data. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Sorry, I should clarify, I meant the chances of the database corruption. You are right, in a properly designed system the access to the database would take into account a changed password, which would be the normal scenario. But, if there is even a small possibility that a database would be "corrupted" because of an extraneous connection (regardless of how well the system is designed), then it could be a problem. The database being unreadable due to a wrong password is good because it is functioning the right way like you stated. It shouldn't however become corrupt. Again, I am quite sure it is simply something that I am doing wrong on my end so I need to revisit all the codepaths for this procedure in my code. Thanks! > From: slav...@bigfraud.org > Date: Mon, 24 Oct 2011 04:45:24 +0100 > To: sqlite-users@sqlite.org > Subject: Re: [sqlite] ChangePassword method problem > > > On 24 Oct 2011, at 4:42am, Farhan Husain wrote: > > > So, I was just wondering how you would deal with multiple processes > > accessing the database. You can't guarantee that all would be closing the > > connection properly. It would seem that if all connections needed to be > > closed before a proper changepassword call can take place, then the chances > > of database corruption would increase in a multi-process/multi-access > > environment. > > How did you expect it to work when you designed the system ? After all, > changing the password to a database when lots of other processes are reading > it would naturally cause problems for those processes. They would all > suddenly start generating errors because they'd be unable to access their > data. > > Simon. > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Ok, so I created a simple program to test the changepassword method. Here it is: using System;using System.IO;using System.Text;using System.Data.SQLite; namespace SQLiteTest{class Program{static void Main(string[] args){// Create an encrypted databasestring connectionString = "Data Source=test.db; Password='password'"; using (SQLiteConnection conn = new SQLiteConnection(connectionString)){conn.Open(); // Explicitly close the connectionconn.Close(); } // Open and close the database againusing (SQLiteConnection conn = new SQLiteConnection(connectionString)){ conn.Open();// Explicitly close the connection conn.Close();} // Open, change the password and then close the database using (SQLiteConnection conn = new SQLiteConnection(connectionString)) {conn.Open(); conn.ChangePassword("changed"); // Explicitly close the connectionconn.Close(); } // Try to open and close the database again connectionString = "Data Source=test.db; Password='changed'"; using (SQLiteConnection conn = new SQLiteConnection(connectionString)){// CRASHES HERE WITH EXCEPTION// File is not a database conn.Open();// Explicitly close the connection conn.Close();} // Delete the database fileif (File.Exists("test.db")) File.Delete("test.db");}}} It basically works all the way up to the "CRASHES HERE" part. Now, if the password had actually changed then the program should work but unfortunately it doesn't (or something else is going wrong). Again, Maybe I am doing something incorrectly so I kept it simple just to check. Visual Studio 2010, Debug x86, .NET 4.0 Client Profile, sqlite-netFx40-binary-bundle-Win32-2010-1.0.76.0 Thanks.. > From: cooljac...@hotmail.com > To: sqlite-users@sqlite.org > Date: Mon, 24 Oct 2011 03:55:03 + > Subject: Re: [sqlite] ChangePassword method problem > > > Sorry, I should clarify, I meant the chances of the database corruption. You > are right, in a properly designed system the access to the database would > take into account a changed password, which would be the normal scenario. > But, if there is even a small possibility that a database would be > "corrupted" because of an extraneous connection (regardless of how well the > system is designed), then it could be a problem. The database being > unreadable due to a wrong password is good because it is functioning the > right way like you stated. It shouldn't however become corrupt. > Again, I am quite sure it is simply something that I am doing wrong on my end > so I need to revisit all the codepaths for this procedure in my code. > Thanks! > > > From: slav...@bigfraud.org > > Date: Mon, 24 Oct 2011 04:45:24 +0100 > > To: sqlite-users@sqlite.org > > Subject: Re: [sqlite] ChangePassword method problem > > > > > > On 24 Oct 2011, at 4:42am, Farhan Husain wrote: > > > > > So, I was just wondering how you would deal with multiple processes > > > accessing the database. You can't guarantee that all would be closing the > > > connection properly. It would seem that if all connections needed to be > > > closed before a proper changepassword call can take place, then the > > > chances of database corruption would increase in a > > > multi-process/multi-access environment. > > > > How did you expect it to work when you designed the system ? After all, > > changing the password to a database when lots of other processes are > > reading it would naturally cause problems for those processes. They would > > all suddenly start generating errors because they'd be unable to access > > their data. > > > > Simon. > > ___ > > sqlite-users mailing list > > sqlite-users@sqlite.org > > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] ChangePassword method problem
Reading your code quickly, it seems the problem may be related to the use of single-quotes (') around the passwords in the connection string. Please remove all the single-quotes and try again. -- Joe Mistachkin ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users