/// <summary> /// Get linked server name by mdb/accdb file path. /// </summary> /// <param name="sMDBPath"></param> /// <returns></returns> public static string GetLinkedSrvName(string sMDBPath) { string sLinkedSrvName; if (_linkedSrvNameDictionary.TryGetValue(sMDBPath, out sLinkedSrvName)) { return(sLinkedSrvName); } sLinkedSrvName = CalculateLinkedSrvName(sMDBPath); CheckSqlLinkedServer(sMDBPath); _linkedSrvNameDictionary[sMDBPath] = sLinkedSrvName; // Evaluate memo tables cache. List <string> memoLst = new List <string>(); using (XDbConnection con = new XDbConnection(GetAceConnectString(sMDBPath))) { if (!_memoTables.TryGetValue(CalculateLinkedSrvName(sMDBPath), out memoLst)) { con.Open(); _memoTables[CalculateLinkedSrvName(sMDBPath)] = GetMemoTableList(con); } } return(sLinkedSrvName); }
private static List <string> GetMemoTableList(XDbConnection con) { List <string> lst = new List <string>(); DataTable dt = new DataTable(); string commandString = string.Format("Exec SP_COLUMNS_EX N'{0}'", XDbEnvironment.CalculateLinkedSrvName(con.InputFile)); using (DbCommand comm = new XDbCommand(commandString, con)) { using (DbDataReader reader = comm.ExecuteReader()) { dt.Load(reader, LoadOption.OverwriteChanges); } // Go through the table rows and search for the memo fields( TYPE_NAME = VarChar && COLUMN_SIZE = 0 ) foreach (DataRow row in dt.Rows) { if ((row["TYPE_NAME"].ToString() == "VarChar") && (row["COLUMN_SIZE"].ToString() == "0")) { if (!lst.Contains(row["TABLE_NAME"].ToString())) { lst.Add(row["TABLE_NAME"].ToString()); } } } } return(lst); }
public void Dispose() { if (m_XDbConnection == null) { return; } try { if (m_XDbConnection.State == ConnectionState.Open) { m_XDbConnection.Close(); } ImportDataSet.Clear(); ImportDataSet.Dispose(); ImportDataSet = null; } catch { } finally { m_XDbConnection = null; } }
private void Initialize() { if (string.IsNullOrEmpty(m_fileName) || !File.Exists(m_fileName)) { string msg = string.Format("{0} does not exist or is null.", string.IsNullOrEmpty(m_fileName) ? "[Invalid file name passed in]" : m_fileName); throw new ApplicationException(msg); } string conStr = XDbEnvironment.GetConnectionString(m_fileName); m_XDbConnection = new XDbConnection(conStr); try { m_XDbConnection.Open(); } catch (Exception ex) { m_XDbConnection = null; ApplicationExceptions.Add(new ApplicationException(ex.Message, ex.InnerException)); return; } m_XDbType = XDbEnvironment.XDbConnectedType; }