Skip to content

[oatpp::sqlite::Executor::getConnection()]: Error. Can't connect #14

@ajinkyabawaskar

Description

@ajinkyabawaskar

I am building a project with the given CMakeLists.txt with conan:

cmake_minimum_required(VERSION 3.1)
set(PROJECT_NAME my-project)
project(${PROJECT_NAME})

set(CMAKE_CXX_STANDARD 14)

############################### CONAN SETUP BEGIN ##########################################
if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
    message(STATUS "Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
    file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.9/conan.cmake"
            "${CMAKE_BINARY_DIR}/conan.cmake")
endif()
include(${CMAKE_BINARY_DIR}/conan.cmake)
conan_cmake_run(CONANFILE conanfile.txt BASIC_SETUP)
############################### CONAN SETUP END ############################################

add_library(${PROJECT_NAME}-lib
        # controllers
        src/controller/StaticController.hpp
        src/controller/DeviceController.hpp

        # db
        src/db/DeviceDb.hpp

        # dto
        src/dto/PageDto.hpp
        src/dto/StatusDto.hpp
        src/dto/DeviceDto.hpp

        # services
        src/service/DeviceService.cpp
        src/service/DeviceService.hpp

        # base
        src/AppComponent.hpp
        src/DatabaseComponent.hpp
        src/ErrorHandler.cpp
        src/ErrorHandler.hpp)

## include directories
target_include_directories(${PROJECT_NAME}-lib PUBLIC src)


add_definitions(
        ## SQLite database file
        -DDATABASE_FILE="${CMAKE_CURRENT_SOURCE_DIR}/sql/db.sqlite"

        ## SQLite database test file
        -DTESTDATABASE_FILE="${CMAKE_CURRENT_SOURCE_DIR}/sql/test-db.sqlite"

        ## Path to database migration scripts
        -DDATABASE_MIGRATIONS="${CMAKE_CURRENT_SOURCE_DIR}/sql"

        ##  Server
        -DHOST="0.0.0.0"
        -DPORT=8080
)

if(CMAKE_SYSTEM_NAME MATCHES Linux)
    find_package(Threads REQUIRED)
    target_link_libraries(${PROJECT_NAME}-lib INTERFACE Threads::Threads ${CMAKE_DL_LIBS})
endif()

## add executables
add_executable(${PROJECT_NAME}-exe src/App.cpp)
target_link_libraries(${PROJECT_NAME}-exe ${PROJECT_NAME}-lib ${CONAN_LIBS})

add_executable(${PROJECT_NAME}-test
        test/tests.cpp
        test/app/TestClient.hpp
        test/app/TestDatabaseComponent.hpp
        test/app/TestComponent.hpp
        test/DeviceControllerTest.hpp
        test/DeviceControllerTest.cpp)

target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME}-lib ${CONAN_LIBS})

enable_testing()
add_test(e2e-tests ${PROJECT_NAME}-test)

Using this yields me a working executable on my machine running ubuntu 20.04. But when I move this executable to a LXD container running ubuntu 20.04, I get the following error:

ubuntu@container:~$ ./my-project-exe 
terminate called after throwing an instance of 'std::runtime_error'
  what():  [oatpp::sqlite::Executor::getConnection()]: Error. Can't connect.
Aborted (core dumped)

ubuntu@container:~$ sudo ./my-project-exe 
terminate called after throwing an instance of 'std::runtime_error'
  what():  [oatpp::sqlite::Executor::getConnection()]: Error. Can't connect.
Aborted (core dumped)

Looks like the database file db.sqlite fails to create. How can I eliminate this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions