1

I have a program that accesses a database using SQLite. When I open a OpenFileDialog or a SaveFileDialog before I do the SQLite call:

result = sqlite3_prepare_v2(databaseConnection,converted,10000,&stmt,&strptr);

and choose "Cancel", everything works okay (result == SQLITE_OK) but when I choose "Open", even if I don't do anything with the dialog's return file, it breaks (result == SQLITE_ERROR). Do you have any idea why this might be happening?

Thanks so much for your time!

EDIT: Here is the code I am using:

OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;
openFileDialog1->ShowDialog();
sqlite3_stmt * stmt;
const char * strptr;
sqlite3 * databaseConnection;

int result = sqlite3_open("virtualpatient_chat.db", &databaseConnection);

if (result != SQLITE_OK) return;
result = sqlite3_prepare_v2(databaseConnection,"SELECT * from mappings;",10000,&stmt,&strptr);

if (result != SQLITE_OK) return;

Strangely, it won't work in my current project but I copied and pasted it into a brand new project and the error doesn't repeat. Now I'm just trying to figure out what the problem in my surrounding code could be...

2
  • 1
    more code would be better especially the OpenFileDialog object construction and ShowDialog call(s).
    – Aamir
    Oct 22, 2010 at 19:52
  • Are you picking the database file using the dialog? You shouldn't be doing anything to the sqlite database file while you have it open (i.e. have a connection to it).
    – Jay
    Oct 22, 2010 at 20:12

2 Answers 2

1

There's no hope to diagnose the source of the problem from the question. Just some pointers.

Start by setting the OpenFileDialog's RestoreDirectory to True. This ensures that clicking Open doesn't change the program's working directory. If that works then there's a rather mysterious dependency on the current directory in the query.

Next thing to worry about are the DLLs that are getting loaded when you use the dialog. Project + Properties, Debug tab, tick "Enable unmanaged code debugging". Check out the Output window when you open the dialog, it shows a list of the DLLs getting injected. These are shell extensions, one of them might conflict with SQLite. No real clue what such an extension might do beyond maybe corrupting memory or using SQLite itself. You can temporarily disable shell extension with the SysInternals' AutoRuns utility. Start with the ones not written by Microsoft.

1

I finally figured out how to fix it. Under the Properties for my dialog box, I had to set the RestoreDirectory property to true. I'm not quite sure how that fixed it unless somehow by changing the directory it made SQLite not be able to find my database file.

Thanks for your help!

1
  • yes, you need to set the RestoreDirectory to true BEFORE executing OpenFileDialog's ShowDialog().
    – Aryo
    Mar 30, 2012 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.