/// <summary> /// This function returns login and password of user for a passed NpgsqlConnection /// </summary> /// <param name="connection">the current opened DbConnection</param> /// <param name="login">returned login corresponding to the NpgsqlConnection passed</param> /// <param name="password">returned password corresponding to the NpgsqlConnection passed</param> /// <returns>true if succeed, false otherwise (connection null or not opened)</returns> public static bool GetConnectionInformationsFrom( IDbConnection connection, out string login, out string password) { login = string.Empty; password = string.Empty; if ((connection != null) && (connection.State == System.Data.ConnectionState.Open)) { DbConnectionStringBuilder builder = new DbConnectionStringBuilder(); builder.ConnectionString = connection.ConnectionString; if (builder != null) { object value = null; bool result = builder.TryGetValue("User Id", out value); if (result) { login = value.ToString(); } result &= builder.TryGetValue("Password", out value); if (result) { password = value.ToString(); } builder.Clear(); return result; } } return false; }
//private void Delete() //{ // Process proc = new Process(); // proc.StartInfo.CreateNoWindow = true; // proc.StartInfo.FileName = "cmd.exe"; // proc.StartInfo.UseShellExecute = false; // proc.StartInfo.RedirectStandardError = true; // proc.StartInfo.RedirectStandardInput = true; // proc.StartInfo.RedirectStandardOutput = true; // proc.Start(); // proc.StandardInput.WriteLine("del " + m_strFilePathName.Substring(0, m_strFilePathName.Length - 3) + "ldb"); // proc.StandardInput.WriteLine("del " + m_strFilePathName); // //proc.StandardInput.WriteLine("delete " + m_strPath + ".tmp.mdb"); // proc.Close(); //} private bool Connect(string strFilePathName) { try { m_strFilePathName = strFilePathName; if (File.Exists(strFilePathName)) { try { File.Delete(strFilePathName); } catch (Exception ee) { //Delete(); strFilePathName += "_1.mdb"; } } try { ADOX.Catalog catalog = new ADOX.Catalog(); catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFilePathName + ";Jet OLEDB:Engine Type=5"); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catalog.ActiveConnection); System.Runtime.InteropServices.Marshal.FinalReleaseComObject(catalog); } catch (Exception ee) { } DbConnectionStringBuilder dcsBuilder = new DbConnectionStringBuilder(); dcsBuilder.Clear(); dcsBuilder.Add("Provider", "Microsoft.Jet.Oledb.4.0"); dcsBuilder.Add("User ID", "Admin"); dcsBuilder.Add("Password", ""); dcsBuilder.Add("Data Source", @strFilePathName); m_pOleDbConnection = new OleDbConnection(dcsBuilder.ConnectionString); m_pOleDbConnection.Open(); //m_pPolygonNodeTable = new PolygonNodeTable(m_pOleDbConnection, true); //m_pLineNodeExTable = new LineNodeExTable(m_pOleDbConnection, true); //m_pLineNodeTable = new LineNodeTable(m_pOleDbConnection, true); return true; } catch (Exception ex) { Logger.WriteErrorLog(ex); } return false; }