1

How to make this to read from custom string the information I would like to read Host,User,Password,Database from the custom string, how can i do that? Also another problem here in code is that it show that is connected with ODBC , but it doesnt read anything from database

    GetPrivateProfileStringA("SQL","Host","127.0.0.1",szServer2,sizeof(szServer2),SQL_PATH);
    GetPrivateProfileStringA("SQL","User","sa",szUser,sizeof(szUser),SQL_PATH);
    GetPrivateProfileStringA("SQL","Password","12345",szPassword,sizeof(szPassword),SQL_PATH);
    GetPrivateProfileStringA("SQL","Database","DbName",szDatabase,sizeof(szDatabase),SQL_PATH);

BOOL SQLCONNECT::Connect()
{
    SQLHENV env;
    SQLHDBC dbc;
    SQLHSTMT stmt;
    SQLRETURN ret;
    SQLSMALLINT columns;
    int row = 0;

    /* Allocate an environment handle */
    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
    /* We want ODBC 3 support */
    SQLSetEnvAttr(env, SQL_ATTR_ODBC_VERSION, (void *)SQL_OV_ODBC3, 0);
    /* Allocate a connection handle */
    SQLAllocHandle(SQL_HANDLE_DBC, env, &dbc);

    /* Connect to the DSN */
    SQLDriverConnectW(dbc, NULL, L"DRIVER={SQL Server};SERVER=(local);DATABASE=DbName;UID=sa;PWD=password;", SQL_NTS, NULL, 0, NULL, SQL_DRIVER_COMPLETE);

    /* Check for success */
    if (SQL_SUCCESS != SQLAllocHandle(SQL_HANDLE_STMT, dbc, &stmt))
    {
        MessageBoxA(0, "Failed to connect to Database!", "Error", MB_OK);
    }

    std::cin.get();
    return FALSE;
}
  • 1
    Do you mean you want to format the string you pass to `SQLDriverConnectW` using the data you read from the `GetPrivateProfileStringA` calls? – Some programmer dude Dec 27 '15 at 14:30
  • but i have another issue with this code, with ODBC connection It run application but it doesnt read at all from Database stuff Column Tables and others, what may be wrong? – Инж.Георги Петев Dec 27 '15 at 14:41
  • Please _edit_ your post and include all the relevant details including clarification of exactly what you're trying to accomplish. i also suggest you concentrate on fixing one bug at a time. – Captain Obvlious Dec 27 '15 at 15:05
  • i had edited it, also i had another thread http://stackoverflow.com/questions/34467780/connection-return-fail-odbc?noredirect=1#comment56678387_34467780 With another method for connection, that works with database read information but here i found this in tutorials and wanted to try it out but it seems its wrong – Инж.Георги Петев Dec 27 '15 at 15:07
  • 3
    Read about [`std::snprintf`](http://en.cppreference.com/w/cpp/io/c/fprintf) (or its [wide-character companion](http://en.cppreference.com/w/cpp/io/c/fwprintf)). Or about [`std::istringstream`](http://en.cppreference.com/w/cpp/io/basic_istringstream) (and it's complement `std::wistringstream`). – Some programmer dude Dec 27 '15 at 15:27
  • wrong answer nothing to do with this, in fact only option is to make SQLDriverConnectW to read custom variables – Инж.Георги Петев Dec 27 '15 at 15:50

0 Answers0