private bool TestOpen(out string psErrMsg, out string psSuccMsg) { string xsErrMsg = "", xsSuccMsg = ""; string xsSrc = txtSrc.Text.Trim(); Cursor xoOrgCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; DB xoDB = new DB(); DatabaseToOpen xoDbToOpen = GetSelectedDatabaseToOpen(); string xs = xoDbToOpen.Provider.ConnectionStringOverride.Trim(); if (xs.Length > 0) { xs = xs.Replace("\r", ""); xoDbToOpen.Provider.ConnectionStringOverride = xs.Replace("\n", ""); } if (xoDB.OpenDatabase(xoDbToOpen)) { xsSuccMsg = "Database successfully connected."; } else { xsErrMsg = xoDB.Message; } msLastConnStr = xoDB.Connection.Info; Cursor.Current = xoOrgCursor; psErrMsg = xsErrMsg; psSuccMsg = xsSuccMsg; return(xsErrMsg.Length == 0); }
//private DatabaseProvider GetSelectedProvider() //{ // DatabaseProvider xoProv = new DatabaseProvider(); // xoProv. // return (xoProv); //} private void btnOpen_Click(object sender, EventArgs e) { const string xcsTitle = "Open Connection"; string xsErrMsg = "", xsSuccMsg = ""; msPswd = txtPswd.Text.Trim(); xsErrMsg = CheckForConnStrMatch(); if (xsErrMsg.Length == 0) { if (TestOpen(out xsErrMsg, out xsSuccMsg)) { moDbToOpen = GetSelectedDatabaseToOpen(); //if (moDbToOpen.UserID.Trim().Length > 0) moDbToOpen.NeedPassword = true; mbOK = true; this.Hide(); } else { Global.ShowMessage(xsErrMsg, xcsTitle); } } else { Global.ShowMessage(xsErrMsg, xcsTitle); } }
public void SetDbToOpen(DatabaseToOpen poDbToOpen) { moDbToOpen = poDbToOpen; MatchConnType(poDbToOpen.ConnectionType); txtSrc.Text = poDbToOpen.DataSource; MatchSrcToDropdown(); txtDB.Text = poDbToOpen.Database; MatchDbToDropdown(); txtUserID.Text = poDbToOpen.UserID; txtPswd.Text = poDbToOpen.Password; string xsConnStrOverride = poDbToOpen.Provider.ConnectionStringOverride.Trim().Replace(Global.EmbeddedSingleQt, "'"); chkManual.Checked = xsConnStrOverride.Length > 0; txtConnStr.Text = xsConnStrOverride; }
private DatabaseToOpen GetSelectedDatabaseToOpen() { DatabaseToOpen xoDbToOpen = new DatabaseToOpen(); string xsConnStrOverride = txtConnStr.Text.Trim(); if (!chkManual.Checked) { xsConnStrOverride = ""; } xoDbToOpen.Description = txtDesc.Text.Trim(); xoDbToOpen.Provider = moProviders[drpProv.SelectedIndex]; xoDbToOpen.Provider.ConnectionStringOverride = xsConnStrOverride; xoDbToOpen.Database = GetSelectedDatabase(); xoDbToOpen.DataSource = GetSelectedDataSource(); xoDbToOpen.ConnectionType = GetSelectedConnType(); xoDbToOpen.UserID = txtUserID.Text.Trim(); xoDbToOpen.Password = txtPswd.Text.Trim(); return(xoDbToOpen); }
public static bool OpenThisAppsDatabase(ref DB poDB) { string xsErrMsg = ""; poDB = new DB(); DatabaseToOpen xoDbToOpen = new DatabaseToOpen(); xoDbToOpen.Provider = poDB.Providers[0]; if (ThisAppsDatabaseUseODBC) { xoDbToOpen.ConnectionType = ConnectivityType.ODBC; } else { xoDbToOpen.ConnectionType = ConnectivityType.OleDB; // test-force fail, to go to ODBC attempt //xoDbToOpen.ConnectionType = ConnectivityType.DotNet; } xoDbToOpen.Database = Global.gsAppDb; if (poDB.OpenDatabase(xoDbToOpen)) { } else { xsErrMsg = poDB.Message; xoDbToOpen.ConnectionType = ConnectivityType.ODBC; if (poDB.OpenDatabase(xoDbToOpen)) { // Jet 4.0 OLE not present, but we can use ODBC instead xsErrMsg = ""; ThisAppsDatabaseUseODBC = true; } } return(xsErrMsg.Length == 0); }
public void RemoveTheDbFromList() { const string xcsCaption = "Remove DB From List"; string xsErrMsg = ""; int xiOrgIdx = lstDBs.SelectedIndex; DatabaseToOpen xoDbToOpen = new DatabaseToOpen(); if (GetDbToOpen(ref xoDbToOpen, out xsErrMsg)) { DB xoAppDB = new DB(); if (Global.OpenThisAppsDatabase(ref xoAppDB)) { mbDbsRemoved = true; mbDbListChanged = true; DataTable xoTbl = new DataTable(); string xsSQL = "SELECT dataSetID FROM Datasets WHERE dbID = " + xoDbToOpen.UniqueID.ToString(); if (xoAppDB.SQL(xsSQL, xoTbl)) { bool xbCont = true; //int xiSets = Convert.ToInt32(xoTbl.Rows[0][0]); int xiSets = xoTbl.Rows.Count; if (xiSets >= 1) { if (Global.ShowMessage("There are " + xiSets.ToString() + " dataset(s) associated to this database which will also be removed. Would you like to continue?", xcsCaption, MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes) { xbCont = false; } } if (xbCont) { if (xiSets > 0) { for (int xiSet = 1; xiSet <= xiSets; xiSet++) { string xsDsID = xoTbl.Rows[xiSet - 1][0].ToString().TrimEnd(); // children xsSQL = "DELETE * FROM [dataset] WHERE dataSetID = '" + xsDsID + "'"; if (!xoAppDB.SQL(xsSQL)) { xsErrMsg = xoAppDB.Message + " (SQL: " + xsSQL + ")"; xbCont = false; break; } // parent xsSQL = "DELETE * FROM [datasets] WHERE dataSetID = '" + xsDsID + "'"; if (!xoAppDB.SQL(xsSQL)) { xsErrMsg = xoAppDB.Message + " (SQL: " + xsSQL + ")"; xbCont = false; break; } } } if (xbCont) { xsSQL = "DELETE * FROM [Database] WHERE [ID] = " + xoDbToOpen.UniqueID.ToString(); if (xoAppDB.SQL(xsSQL)) { lstDBs.Items.RemoveAt(xiOrgIdx); mrLoadedDbs.RemoveAt(xiOrgIdx); UpdateControlsAvailability(); } else { xsErrMsg = xoAppDB.Message + " (SQL: " + xsSQL + ")"; } } } } ReleaseTable(ref xoTbl); } else { xsErrMsg = xoAppDB.Message; } Global.CloseThisAppsDatabase(ref xoAppDB); } else { xsErrMsg = "Unable to locate internal database ID."; } UpdateControlsAvailability(); if (xsErrMsg.Length > 0) { Global.ShowMessage(xsErrMsg, xcsCaption); } }
private bool GetDbToOpen(ref DatabaseToOpen prDbToOpen, out string psErrMsg) { string xsErrMsg = ""; if (lstDBs.SelectedIndex < 0) { for (int xii = 0; xii < mrLoadedDbs.Count; xii++) { if (mrLoadedDbs[xii].Database.Trim().ToUpper() == prDbToOpen.Database.Trim().ToUpper()) { lstDBs.SelectedIndex = xii; break; } } } if (lstDBs.SelectedIndex >= 0) { DB xoAppDB = new DB(); int xiID = mrLoadedDbs[lstDBs.SelectedIndex].ID; if (Global.OpenThisAppsDatabase(ref xoAppDB)) { DataTable xoTbl = new DataTable(); xoTbl.Reset(); string xsSQL = "SELECT connType, providerName, source, [database], userID, connStr FROM [database] WHERE ID = " + xiID.ToString(); if (xoAppDB.SQL(xsSQL, xoTbl)) { if (xoTbl.Rows.Count > 0) { prDbToOpen.UniqueID = xiID; DatabaseProvider xrProv = new DatabaseProvider(); string xsProv = null2str(xoTbl.Rows[0][1].ToString()).TrimEnd().ToUpper(); if (xsProv.Length > 0) { for (int xii = 0; xii < xoAppDB.Providers.Count; xii++) { if (xsProv == xoAppDB.Providers[xii].Name.TrimEnd().ToUpper()) { xrProv = xoAppDB.Providers[xii]; break; } } } xrProv.ConnectionStringOverride = xoTbl.Rows[0][5].ToString().TrimEnd(); prDbToOpen.Provider = xrProv; prDbToOpen.ConnectionType = (ConnectivityType)xoAppDB.null2int(xoTbl.Rows[0][0]); prDbToOpen.DataSource = xoTbl.Rows[0][2].ToString().TrimEnd(); prDbToOpen.Database = xoTbl.Rows[0][3].ToString().TrimEnd(); prDbToOpen.UserID = xoTbl.Rows[0][4].ToString().TrimEnd(); //bool xbNeedPswd = false; //if (xoTbl.Rows[0][5] != null) xbNeedPswd = Convert.ToBoolean(xoTbl.Rows[0][5]); //prDbToOpen.NeedPassword = true; } else { xsErrMsg = "Database connection record not found.\r\n(SQL: " + xsSQL + ") (ID: " + xiID.ToString(); } } else { xsErrMsg = xoAppDB.Message + "\r\n(SQL: " + xsSQL + ")"; } ReleaseTable(ref xoTbl); Global.CloseThisAppsDatabase(ref xoAppDB); } else { xsErrMsg = xoAppDB.Message; } } psErrMsg = xsErrMsg; return(xsErrMsg.Length == 0); }