How to swallow … exception with specific reason
问题 In this method public static void Detach() { try { using (var master = new DataContext(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True")) { master.ExecuteCommand(string.Format("ALTER DATABASE [{0}] SET OFFLINE WITH ROLLBACK IMMEDIATE", DatabaseFile)); master.ExecuteCommand(string.Format("exec sp_detach_db '{0}'", DatabaseFile)); } } catch (Exception e) { ... // add to log } } I can receive exception System.Data.SqlClient.SqlException (0x80131904): The