andreasen
May 18th, 2004, 09:06 AM
I am running into an unknown error when I try to set OleDB.ConnectionString.
Here is the Error Message
An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.
Additional information: Object reference not set to an instance of an object.
The error only occurs when I retrieve the DB path from a fileBrowserDialog in cases where a default DB file does not exist. I've compared a working and non-working string (where I only change the default DB name and force the file browser logic). In my test case, the difference is limited to the name change:
working
"Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=C:\\test\\test.mdb;Mode=ReadWrite"
non-working
"Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=C:\\test\\test1.mdb;Mode=ReadWrite"
The code has the defined try-catch block for ConnectionString access, but this is not being trapped in that. I've also verified that the file permissions are correct on the DB (by changing the default name to invoke the file browser on a DB that worked) and tested variations on the path (moving the default expectation to other directories, etc.). The problem seems to boil down to the use of the FileBrowser.
Does anyone have any ideas what is happening and how to correct it?
Thanks.
-b
p.s. The code to retrieve the FileBrowserDialog selection is:
System.Windows.Forms.OpenFileDialog DBBrowserDialog;
DBBrowserDialog = new System.Windows.Forms.OpenFileDialog();
DBBrowserDialog.Title = "Select database file";
DBBrowserDialog.Multiselect = false;
DBBrowserDialog.InitialDirectory = Environment.CurrentDirectory;
DBBrowserDialog.DefaultExt = "mdb";
if (DBBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
else
dbPath = DBBrowserDialog.FileName;
Here is the Error Message
An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.
Additional information: Object reference not set to an instance of an object.
The error only occurs when I retrieve the DB path from a fileBrowserDialog in cases where a default DB file does not exist. I've compared a working and non-working string (where I only change the default DB name and force the file browser logic). In my test case, the difference is limited to the name change:
working
"Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=C:\\test\\test.mdb;Mode=ReadWrite"
non-working
"Provider=Microsoft.Jet.OLEDB.4.0;Password=\"\";User ID=Admin;Data Source=C:\\test\\test1.mdb;Mode=ReadWrite"
The code has the defined try-catch block for ConnectionString access, but this is not being trapped in that. I've also verified that the file permissions are correct on the DB (by changing the default name to invoke the file browser on a DB that worked) and tested variations on the path (moving the default expectation to other directories, etc.). The problem seems to boil down to the use of the FileBrowser.
Does anyone have any ideas what is happening and how to correct it?
Thanks.
-b
p.s. The code to retrieve the FileBrowserDialog selection is:
System.Windows.Forms.OpenFileDialog DBBrowserDialog;
DBBrowserDialog = new System.Windows.Forms.OpenFileDialog();
DBBrowserDialog.Title = "Select database file";
DBBrowserDialog.Multiselect = false;
DBBrowserDialog.InitialDirectory = Environment.CurrentDirectory;
DBBrowserDialog.DefaultExt = "mdb";
if (DBBrowserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
{
return;
}
else
dbPath = DBBrowserDialog.FileName;