///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// internal static DSLConnectionHolder GetConnection(string dbFileName, bool revertImpersonation) { dbFileName = dbFileName.Trim(); ///////////////////////////////////////////////// // Lock the connections table, and see if it already exists lock (_Connections) { DSLConnectionHolder holder = (DSLConnectionHolder)_Connections[dbFileName]; if (holder != null && !File.Exists(holder.Connection.DataSource)) { _Connections.Remove(dbFileName); holder = null; } if (holder == null) { BuildConnectionForFileName(dbFileName); holder = (DSLConnectionHolder)_Connections[dbFileName]; } if (holder == null) { return(null); } holder.Open(null); return(holder); } }
///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// internal static Exception GetBetterException(Exception e, DSLConnectionHolder holder) { try { if (!(e is SqlException) || holder.Connection == null || holder.Connection.DataSource == null || holder.Connection.DataSource.Length < 1) { return(e); } if (!File.Exists(holder.Connection.DataSource)) { return(new FileNotFoundException(String.Empty, holder.Connection.DataSource, e)); } } finally { if (holder.Connection != null) { holder.Connection.Close(); } } FileStream s = null; Exception eWrite = null; try { s = File.OpenWrite(holder.Connection.DataSource); } catch (Exception except) { eWrite = except; } finally { if (s != null) { s.Close(); } } if (eWrite != null && (eWrite is UnauthorizedAccessException)) { HttpContext context = HttpContext.Current; if (context != null) { context.Response.Clear(); context.Response.StatusCode = 500; context.Response.Write("Cannot write to DB File"); context.Response.End(); } return(new Exception("AccessFile is not writtable", eWrite)); } return(e); }