This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, I have discovered something unexpected - as most discoveries are, I suppose :) - with respect to a SQLite connection string and a WinForms OpenFileDialog control. C#, .NET 3.5, LightSpeed Professional 2.2.948.10429, Visual Studio 2008 I have an App.config with a connection string defined as: The database is stored in the application executable directory and everything works fine with all operations to the database with one exception. On this form is an ordinary button which, when clicked, invokes an ordinary OpenFileDialog dialog. Now, I use that dialog to navigate to a directory outside of my executable directory, select a file and close the dialog. Next, I create an IUnitOfWork and SaveChanges(). During the Savechanges(), I receive an exception concerning tables not available. Further, a zero byte MyApp.db (from my connection string) is created in the directory I was in in the OpenFileDialog. If I change my connection string to be absolute rather than relative, all works as expected. If I never invoke my OpenFileDialog, all works as expected. My first guess is that I am doing something wrong but all my docs suggest I have an appropriate connection string for a 'database that lives in the executable directory'. My theory is that the 'current directory' changes due to the OpenFileDialog and so my Lightspeed context is changing with it and so the database technically changes location. I can certainly create a complete example of this but I am writing first to see if this all sounds normal and I've just neglected something important. Any comments or suggestions welcome. Best regards for any assistance. Thank you, |
|
|
The "." refers to the current directory, which is not necessarily the executable directory. And as you have guessed, OpenFileDialog can change the current directory. Check out the FileDialog.RestoreDirectoryProperty:
So setting this to true should fix your problem, though whether this is viable depends on whether other code depends on the changed working directory. Another option to consider is to put your database not in the executable directory, but in a per-user or shared data directory. Depending on your deployment scenario, storing data in Program Files
may be problematic anyway on Vista and above because of elevation
requirements. See Environment.GetSpecialFolder for getting suitable paths. |
|
|
Thank you Ivan, I appreciate you time very much. I moved the database to Environment.SpecialFolder.CommonApplicationData\... which is ultimately where it belongs. It just seemed weird to me that the database connection would change depending on the current directory of the application... learn something new every day! Once again, thank you very much for your time. Have a great day. Lionel |
|