diff --git a/common/database/database_connection.cpp b/common/database/database_connection.cpp index 06f17eeb94..ea023c9034 100644 --- a/common/database/database_connection.cpp +++ b/common/database/database_connection.cpp @@ -348,6 +348,10 @@ bool DATABASE_CONNECTION::SelectOne( const std::string& aTable, m_lastError = e.what(); wxLogTrace( traceDatabase, wxT( "Exception while preparing statement for SelectOne: %s" ), m_lastError ); + + // Exception may be due to a connection error; nanodbc won't auto-reconnect + m_conn->disconnect(); + return false; } @@ -365,6 +369,10 @@ bool DATABASE_CONNECTION::SelectOne( const std::string& aTable, m_lastError = e.what(); wxLogTrace( traceDatabase, wxT( "Exception while executing statement for SelectOne: %s" ), m_lastError ); + + // Exception may be due to a connection error; nanodbc won't auto-reconnect + m_conn->disconnect(); + return false; } @@ -434,6 +442,10 @@ bool DATABASE_CONNECTION::SelectAll( const std::string& aTable, std::vector m_lastError = e.what(); wxLogTrace( traceDatabase, wxT( "Exception while preparing query for SelectAll: %s" ), m_lastError ); + + // Exception may be due to a connection error; nanodbc won't auto-reconnect + m_conn->disconnect(); + return false; } @@ -448,6 +460,10 @@ bool DATABASE_CONNECTION::SelectAll( const std::string& aTable, std::vector m_lastError = e.what(); wxLogTrace( traceDatabase, wxT( "Exception while executing query for SelectAll: %s" ), m_lastError ); + + // Exception may be due to a connection error; nanodbc won't auto-reconnect + m_conn->disconnect(); + return false; } diff --git a/eeschema/sch_plugins/database/sch_database_plugin.cpp b/eeschema/sch_plugins/database/sch_database_plugin.cpp index 0fbd519328..5ea382b7c3 100644 --- a/eeschema/sch_plugins/database/sch_database_plugin.cpp +++ b/eeschema/sch_plugins/database/sch_database_plugin.cpp @@ -251,6 +251,9 @@ void SCH_DATABASE_PLUGIN::ensureConnection() { wxCHECK_RET( m_settings, "Call ensureSettings before ensureConnection!" ); + if( m_conn && !m_conn->IsConnected() ) + m_conn.reset(); + if( !m_conn ) { if( m_settings->m_Source.connection_string.empty() )