/// <summary> /// Shows the OleDb connection dialog. /// </summary> /// <returns>A DialogResult value, determining, if the dialog was cancelled or the OK button was pressed.</returns> public DialogResult Show() { Type t = Type.GetTypeFromCLSID(new Guid("{00000514-0000-0010-8000-00AA006D2EA4}")); object oc = Activator.CreateInstance(t); if (oc == null) { throw new Exception("Can't construct a Connection object"); } Connection15 cn = (Connection15)oc; if (cn == null) { throw new Exception("Can't get the connection interface"); } t = Type.GetTypeFromCLSID(new Guid("{2206CDB2-19C1-11D1-89E0-00C04FD7A829}")); object odl = Activator.CreateInstance(t); if (odl == null) { throw new Exception("Can't construct a DataLinksClass object"); } IDataSourceLocator dl = (IDataSourceLocator)odl; if (dl == null) { throw new Exception("Can't get the IDataSourceLocator interface"); } cn.ConnectionString = this.connectionString; int trials = 0; while (true) { try { dl.PromptEdit(ref oc); break; } catch (COMException ex) { if (trials > 0) { throw ex; } trials++; cn.ConnectionString = null; } } this.connectionString = cn.ConnectionString; if (cn.ConnectionString == null) { return(DialogResult.Cancel); } else { return(DialogResult.OK); } }
public DialogResult Show() { Type t = Type.GetTypeFromCLSID(new Guid("{00000514-0000-0010-8000-00AA006D2EA4}")); object oc = Activator.CreateInstance(t); if (oc == null) { throw new Exception("Can't construct a Connection object"); } Connection15 cn = (Connection15)oc; if (cn == null) { throw new Exception("Can't get the connection interface"); } t = Type.GetTypeFromCLSID(new Guid("{2206CDB2-19C1-11D1-89E0-00C04FD7A829}")); object odl = Activator.CreateInstance(t); if (odl == null) { throw new Exception("Can't construct a DataLinksClass object"); } IDataSourceLocator dl = (IDataSourceLocator)odl; if (dl == null) { throw new Exception("Can't get the IDataSourceLocator interface"); } cn.ConnectionString = this.connectionString; try { dl.PromptEdit(ref oc); } catch (COMException ex) { if (ex.ErrorCode == -2147217887) { throw new Exception("Wrong connection string format - delete your connection string and press the edit button again."); } else { throw ex; } } this.connectionString = cn.ConnectionString; if (cn.ConnectionString == null) { return(DialogResult.Cancel); } else { return(DialogResult.OK); } }