Grawsha,
You can change the connection string after the InitializeComponent();
without a problem. The Connection object will not give you an error until
it is used. This way you can go ahead and decl. and insta. it in the
InitializeComponent(); routine.
Here is some sample code that works for me.
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
String connectStr = @"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry
Path=;Jet OLEDB
atabase Locking Mode=1;Mode=Share Deny None;Jet
OLEDB:Engine Type=5;Provider=""Microsoft.Jet.OLEDB.4.0"";Jet OLEDB:System
database=;Jet OLEDB:SFP=False;persist security info=False;Extended
Properties=;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:Encrypt
Database=False;Jet OLEDB:Create System Database=False;Jet OLEDB
on't Copy
Locale on Compact=False;User ID=Admin;Jet OLEDB:Global Bulk
Transactions=1;Data Source=";
// String X = @"....""....";
if (File.Exists(mySettings.DataBaseName))
{
connectStr += "\"" + mySettings.DataBaseName + "\"";
}
else
{
openFileDialog1.Title = "Find the Pacer97.mdb file!";
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "Access Files (*.mdb)|*.mdb";
openFileDialog1.FilterIndex = 2;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
connectStr += "\"" + openFileDialog1.FileName + "\"";
mySettings.DataBaseName = openFileDialog1.FileName;
}
}
cn.ConnectionString = connectStr;