Display Dialog problem - tough

bonedoc

Well-known member
Joined
May 4, 2006
Messages
112
Programming Experience
Beginner
I have a dialog that selects a file. If I select one from the floppy drive, the next time I try to access my database, the application crashes at DataBaseConnection.Open(). I have done a watch on the connection string, and it is correct. BUT, for some reasono it tries to access the floppy drive even though the connection string does not mention it at all. I know that a dialog to select a file has a memory that opens the same file each time the dialog is opened, to save the user time. Does anyone know how this may interfere with a connection string or the opening of a database connection? Is there anything that I may watch or a stack I can view or something to figure this behaviour out. It is very odd. I do not tell the code anywhere to refer to the floppy drive, and I do not tell it to change the connection string at any point. The error I get with this is "Disk or Network Error", because it is trying to access the floppy when then databaseconnection is being opened, even though the floppy is not there and has nothing to do with the current code.
 
bonedoc said:
I have a dialog that selects a file. If I select one from the floppy drive, the next time I try to access my database, the application crashes at DataBaseConnection.Open(). I have done a watch on the connection string, and it is correct. BUT, for some reasono it tries to access the floppy drive even though the connection string does not mention it at all. I know that a dialog to select a file has a memory that opens the same file each time the dialog is opened, to save the user time. Does anyone know how this may interfere with a connection string or the opening of a database connection? Is there anything that I may watch or a stack I can view or something to figure this behaviour out. It is very odd. I do not tell the code anywhere to refer to the floppy drive, and I do not tell it to change the connection string at any point. The error I get with this is "Disk or Network Error", because it is trying to access the floppy when then databaseconnection is being opened, even though the floppy is not there and has nothing to do with the current code.

Maybe set the default directory to a directory on the hard disk?
 
Generally speaking, if you don't specify the full path of a file then the current directory is assumed. If you open a FileDialog then the current directory is probably being changed. Firstly, you should NEVER just assume a directory. You should ALWAYS specify the full path of a file, either absolutely or relative to something like Application.StartupPath. Relying on the current directory being something specific is asking for trouble. Secondly, FileDialogs have a property named RestoreDirectory that, when set to True, will reset the current directory to its original value after the user selects a file. Always explore the members of the classes you're using.
 
Back
Top