从连接文件中读取自定义字符串

时间:2015-12-27 14:24:43

标签: c++

如何使其从自定义字符串中读取信息 我想从自定义字符串中读取主机,用户,密码,数据库,我该怎么做? 此处代码中的另一个问题是它显示与ODBC连接,但它不会从数据库中读取任何内容

    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;
}

0 个答案:

没有答案