// This method is to show you, how to load a pre-defined named connection xml file. // sample_namedConnection.xml is the file that we loaded. // private void LoadNamedConnectionMenuItem_Click(object sender, System.EventArgs e) { System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); openFileDialog1.Multiselect = false; openFileDialog1.CheckFileExists = true; openFileDialog1.DefaultExt = "XML"; openFileDialog1.Filter = "Named Connection (*.xml)|*.xml||"; openFileDialog1.FileName = "sample_namedConnection.xml"; if (openFileDialog1.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { try { Session.Current.Catalog.NamedConnections.Load(openFileDialog1.FileName); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } MessageBox.Show(openFileDialog1.FileName + " is loaded."); } // code shows, how to enumerate a collection of named connections System.Collections.IDictionaryEnumerator eu = Session.Current.Catalog.NamedConnections.GetEnumerator(); int i = 0; while (eu.MoveNext()) { NamedConnectionInfo info = eu.Value as NamedConnectionInfo; string aline = string.Format("named connection {0}:{1}:{2},{3},{4}", i, eu.Key, info.DBType, info.ConnectionMethod, info.ConnectionString); MessageBox.Show(aline); ++i; } }
private void AddNamedConnectionMenuItem_Click(object sender, System.EventArgs e) { // create a named connection called "mylocalData" and point it to "c:\mylocal\maps" NamedConnectionInfo info = new NamedConnectionInfo("file", ConnectionMethod.FilePath, @"c:\mylocal\maps"); Session.Current.Catalog.NamedConnections.Add("mylocalData", info); MessageBox.Show(@"A hard coded named connection, mylocalData (which points to 'c:\mylocal\maps'), is added"); }