Mysz nocny
Mysz nocny

Reputation: 41

MariaDB connector c ++ memory protection violation

I am having a problem connecting to the database using MariaDB. When I try to do anything with conn, it prints a memory violation. I use Linux Mint 20.1!!

#include <iostream>
#include <memory>
#include <mariadb/conncpp.hpp>

int main(int argc, char**argv)
{
      sql::Driver* driver = sql::mariadb::get_driver_instance();

      sql::SQLString url("///");
      sql::SQLString base("///");
      std::cout << driver->getName() << std::endl;
      sql::Properties properties({
            {"base", "base"},
            {"password", "password"}
         });

      sql::Connection*conn = driver->connect(url,properties);
      conn->setSchema(base);// here
}

Does anyone know what the problem is? Thank you in advance for your help.

Upvotes: 0

Views: 118

Answers (1)

Lawrin Novitsky
Lawrin Novitsky

Reputation: 141

driver->connect may return nullptr. I guess that is happening. You don't check conn. There is also DriverManager::getConnection, that unlike Driver::connect will throw an exception in such case.

Upvotes: 3

Related Questions