Browse Source

DbLib: Reconnect if connection is lost

7.0
Jon Evans 3 years ago
parent
commit
66799b60f8
  1. 16
      common/database/database_connection.cpp
  2. 3
      eeschema/sch_plugins/database/sch_database_plugin.cpp

16
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<ROW>
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<ROW>
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;
}

3
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() )

Loading…
Cancel
Save