To znów ja :} Tym razem mam problem z połączeniem się z bazą, zorbiłem to:
W PostgreSQL:
- CREATE USER robert WITH ENCRYPTED PASSWORD 'haslo';
- CREATE DATABASE testDB;
- GRANT ALL PRIVILEGES ON DATABASE testDB TO robert;
I mam kod w C++ :
#include <iostream>
#include <soci.h>
#include <string>
using std::string;
using std::cout;
#include <postgresql/soci-postgresql.h>
bool connectToDatabase(string databaseName, string user, string password)
{
try
{
soci::session sql(soci::postgresql, "dbname=" +databaseName + " user="+user + " password="+password);
}
catch (soci::postgresql_soci_error const & e)
{
std::cerr << "PostgreSQL error: " << e.sqlstate() << " " << e.what() << std::endl;
return false;
}
catch (std::exception const & e)
{
std::cerr << "Some other error: " << e.what() << std::endl;
return false;
}
return true;
}
int main(int argc, char **argv)
{
cout << connectToDatabase("testDB", "robert", "haslo");
return 0;
}
a przy kompilacji dostaję błąd:
Some other error: Cannot establish connection to the database.
FATAL: database "testDB" does not exist
??