Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ajinkyabawaskar opened this issue Sep 8, 2021 · 3 comments
Open

Comments

@ajinkyabawaskar
Copy link

ajinkyabawaskar commented Sep 8, 2021

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?

@lizemin5235
Copy link

<migration.migrate(); // <-- run migrations. This guy will throw on error.> how to deal this error

@lganzzzo
Copy link
Member

Hey @ajinkyabawaskar ,

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

Please make sure you have permissions to create file.

@lganzzzo
Copy link
Member

<migration.migrate(); // <-- run migrations. This guy will throw on error.> how to deal this error

@lizemin5235 , you can use try - catch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants