views:

32

answers:

2

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...

+1  A: 

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.

Hans Passant
A: 

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!

laurenelizabeth