Visual Studio 2013: c++ How to make in this function if connection = false show message and close MessageBoxA(0, "Failed to connect to Database!", "Error", MB_OK); ::ExitProcess(0);
if user, password, database = false show message its ODBC connection, and even if i write User = WrongName and Password = WrongPassword still running application without error for connection to database, if i change Database = MuOnline2 Application is going on Loopssss and doesnt start even
my .h file
#ifndef _SQLCONNECT_H
#define _SQLCONNECT_H
//-- SQL
#include <sql.h>
#include <sqltypes.h>
#include <sqlext.h>
//------
void ReadySQLConnect();
#define MAX_COLUMNS 100
class SQLCONNECT
{
public:
    SQLCONNECT();
    virtual ~SQLCONNECT();
    BOOL Connect();
    BOOL Execute(LPTSTR lpszStatement, ...);
    void Close();
    void GetAsString(LPTSTR ColName, LPTSTR pOutBuffer);
    DWORD GetAsInteger(LPTSTR ColName);
    QWORD GetAsInteger64(LPTSTR ColName);
    float GetAsFloat(LPTSTR ColName);
    void Disconnect();
    int GetAsBinary(LPSTR lpszStatement, LPBYTE OUT lpszReturnBuffer);
    SQLRETURN Fetch();
    int GetResult(int iIndex);
    QWORD GetResult64(int iIndex);
    void SetAsBinary(LPTSTR lpszStatement, LPBYTE lpBinaryBuffer, SQLUINTEGER BinaryBufferSize);
    DWORD GetRowCount();
    BOOL ReConnect();
private:
    int FindIndex(LPTSTR ColName);
    void Diagnosis(char* Query);
protected:
    SQLHANDLE m_hEnviroment;
    SQLHANDLE m_hConnection;
    SQLHANDLE m_hStmt;
    TCHAR m_szUser[64];
    TCHAR m_szPassword[64];
    TCHAR m_szDatabase[64];
    SQLINTEGER m_RowCount;
    SQLSMALLINT m_ColCount;
    SQLTCHAR m_SQLColName[MAX_COLUMNS][30];
    TCHAR m_SQLData[MAX_COLUMNS][256];
    SQLINTEGER m_SQLDataLen[MAX_COLUMNS];
};
extern SQLCONNECT cSQL;
void ReadyTableInstallation();
#endif
my .cpp file
#include "StdAfx.h"
SQLCONNECT cSQL;
void ReadySQLConnect()
{
    //cSQL.Connect();
    if (cSQL.Connect() == FALSE)
    {
        MessageBoxA(0, "Failed to connect to Database!", "Error", MB_OK);
    }
}
SQLCONNECT::SQLCONNECT()
{
    this->m_ColCount = -1;
    this->m_hConnection = NULL;
    this->m_hEnviroment = NULL;
    this->m_hStmt = NULL;
    memset(this->m_SQLColName, 0, sizeof(this->m_SQLColName));
    memset(this->m_SQLData, 0, sizeof(this->m_SQLData));
    SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &this->m_hEnviroment);
    SQLSetEnvAttr(this->m_hEnviroment, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_NTS);
}
SQLCONNECT::~SQLCONNECT()
{
    if (this->m_hStmt != SQL_NULL_HANDLE)
        SQLFreeHandle(SQL_HANDLE_STMT, this->m_hStmt);
    if (this->m_hConnection != SQL_NULL_HANDLE)
        SQLFreeHandle(SQL_HANDLE_DBC, this->m_hConnection);
    if (this->m_hEnviroment != SQL_NULL_HANDLE)
        SQLFreeHandle(SQL_HANDLE_ENV, this->m_hEnviroment);
}
BOOL SQLCONNECT::Connect()
{
    GetPrivateProfileStringA("SQL", "User", "sa", this->m_szUser, 64, SQL_PATH);
    GetPrivateProfileStringA("SQL", "Password", "123456", this->m_szPassword, 64, SQL_PATH);
    GetPrivateProfileStringA("SQL", "Database", "MuOnline", this->m_szDatabase, 64, SQL_PATH);
    SQLHANDLE rgbValue;
    SQLAllocHandle(SQL_HANDLE_DBC, this->m_hEnviroment, &this->m_hConnection);
    SQLSetConnectAttr(this->m_hConnection, SQL_LOGIN_TIMEOUT, &rgbValue, 0);
    SQLRETURN Result = SQLConnect(this->m_hConnection, (SQLTCHAR *)this->m_szDatabase, SQL_NTS,
        (SQLTCHAR *)this->m_szUser, SQL_NTS, (SQLTCHAR *)this->m_szPassword, SQL_NTS);
    if (Result != SQL_SUCCESS && Result != SQL_SUCCESS_WITH_INFO)
    {
        SQLSMALLINT sRecord = 1, MsgLen;
        SQLTCHAR SqlState[6], SQLMsgError[SQL_MAX_MESSAGE_LENGTH];
        SQLINTEGER NativeError;
        if (SQLGetDiagRec(SQL_HANDLE_DBC, this->m_hConnection, sRecord, SqlState, &NativeError, SQLMsgError, sizeof(SQLMsgError), &MsgLen) != SQL_NO_DATA)
        {
            //cLog.ConsoleOutput("SQLSTATE:%s, Diagnosis:%s", SqlState, SQLMsgError);
        }
        return FALSE;
    }
    Result = SQLAllocHandle(SQL_HANDLE_STMT, this->m_hConnection, &this->m_hStmt);
    if (Result != SQL_SUCCESS && Result != SQL_SUCCESS_WITH_INFO)
    {
        return FALSE;
    }
    //cLog.ConsoleOutput("[SQL] Connection successfully");
    ReadyTableInstallation();
    return TRUE;
}
BOOL SQLCONNECT::ReConnect()
{
    return this->Connect();
}
BOOL SQLCONNECT::Execute(TCHAR * lpszStatement, ...)
{
    TCHAR szStatement[1024];
    va_list pArguments;
    va_start(pArguments, lpszStatement);
    //wvsprintf(szStatement, lpszStatement, pArguments);
    vsprintf(szStatement, lpszStatement, pArguments);
    va_end(pArguments);
    SQLRETURN Result = SQLExecDirect(this->m_hStmt, (SQLTCHAR *)szStatement, SQL_NTS);
    if (Result != SQL_SUCCESS && Result != SQL_SUCCESS_WITH_INFO && Result != SQL_NO_DATA)
    {
        this->Diagnosis(szStatement);
        return FALSE;
    }
    SQLRowCount(this->m_hStmt, &this->m_RowCount);
    SQLNumResultCols(this->m_hStmt, &this->m_ColCount);
    if (this->m_ColCount >= MAX_COLUMNS - 1)
    {
        //cLog.ConsoleOutput("[CQuery] ColCount >= MAX_COLUMNS-1");
        return FALSE;
    }
    // Case just EXEC
    if (this->m_ColCount == 0)
    {
        this->Close();
        return TRUE;
    }
    for (int iColPos = 0; iColPos < this->m_ColCount; iColPos++)
    {
        memset(this->m_SQLData[iColPos], 0, sizeof(this->m_SQLData[iColPos]));
        SQLBindCol(this->m_hStmt, iColPos + 1, SQL_CHAR, this->m_SQLData[iColPos],
            sizeof(this->m_SQLData[0]) - 1, &this->m_SQLDataLen[iColPos]);
        SQLDescribeCol(this->m_hStmt, iColPos + 1, this->m_SQLColName[iColPos],
            sizeof(this->m_SQLColName[iColPos]), NULL, NULL, NULL, NULL, NULL);
    }
    return TRUE;
}
void SQLCONNECT::Close()
{
    SQLCloseCursor(this->m_hStmt);
    SQLFreeStmt(this->m_hStmt, 2);
}
SQLRETURN SQLCONNECT::Fetch()
{
    return SQLFetch(this->m_hStmt);
}
DWORD SQLCONNECT::GetRowCount()
{
    return this->m_RowCount;
}
int SQLCONNECT::FindIndex(LPTSTR ColName)
{
    for (short i = 0; i<this->m_ColCount; i++)
    {
        if (this->m_SQLColName[i][0] == ColName[0])
        {
            if (lstrcmp((TCHAR *)this->m_SQLColName[i], (TCHAR *)ColName) == 0)
            {
                return i;
            }
        }
    }
    return -1;
}
void SQLCONNECT::GetAsString(LPTSTR ColName, LPTSTR pOutBuffer)
{
    int iIndex = this->FindIndex(ColName);
    if (iIndex != -1)
    {
        lstrcpy(pOutBuffer, this->m_SQLData[iIndex]);
    }
    else
    {
        pOutBuffer[0] = 0;
    }
}
DWORD SQLCONNECT::GetAsInteger(LPTSTR ColName)
{
    int iIndex = this->FindIndex(ColName);
    if (iIndex != -1)
    {
        return atoi(this->m_SQLData[iIndex]);
    }
    return -1;
}
QWORD SQLCONNECT::GetAsInteger64(LPTSTR ColName)
{
    int iIndex = this->FindIndex(ColName);
    if (iIndex != -1)
    {
        return _atoi64(this->m_SQLData[iIndex]);
    }
    return -1;
}
float SQLCONNECT::GetAsFloat(LPTSTR ColName)
{
    int iIndex = this->FindIndex(ColName);
    if (iIndex != -1)
    {
        return (float)atof(this->m_SQLData[iIndex]);
    }
    return -1;
}
void SQLCONNECT::Diagnosis(char* Query)
{
    SQLSMALLINT sRecord = 1, MsgLen;
    SQLTCHAR SqlState[6], SQLMsgError[SQL_MAX_MESSAGE_LENGTH];
    SQLINTEGER NativeError;
    while (SQLGetDiagRec(SQL_HANDLE_STMT, this->m_hStmt, sRecord,
        SqlState, &NativeError, SQLMsgError, sizeof(SQLMsgError), &MsgLen) != SQL_NO_DATA)
    {
        //cLog.ConsoleOutput("SQLSTATE:%s, Diagnosis:%s - %s", SqlState, SQLMsgError, Query);
        sRecord++;
    }
    if (!lstrcmp((TCHAR *)SqlState, "08S01"))   // Communication Link Failure
        this->ReConnect();
}
int SQLCONNECT::GetResult(int iIndex)
{
    return atoi(this->m_SQLData[iIndex]);
}
QWORD SQLCONNECT::GetResult64(int iIndex)
{
    return _atoi64(this->m_SQLData[iIndex]);
}
int SQLCONNECT::GetAsBinary(LPTSTR lpszStatement, LPBYTE OUT lpszReturnBuffer)
{
    SQLCHAR * pSQLBuf;
    SQLINTEGER BufLen;
    SQLCHAR SQLBinary[10000];
    SQLINTEGER lOfs = 0;
    SQLINTEGER SQLLen;
    SQLRETURN SQLResult;
    //SQLAllocHandle(SQL_HANDLE_STMT, this->m_hConnection, &this->m_hStmt);
    SQLResult = SQLExecDirect(this->m_hStmt, (SQLTCHAR *)lpszStatement, SQL_NTS);
    if (SQLResult != SQL_SUCCESS)
    {
        this->Diagnosis(lpszStatement);
        return -1;
    }
    while (true)
    {
        SQLResult = SQLFetch(this->m_hStmt);
        if (SQLResult == SQL_NO_DATA)
            break;
        pSQLBuf = lpszReturnBuffer;
        while (true)
        {
            SQLResult = SQLGetData(this->m_hStmt,
                1, SQL_C_BINARY, SQLBinary, sizeof(SQLBinary), &SQLLen);
            if (SQLResult == SQL_NO_DATA)
                break;
            if (SQLLen == -1)
            {
                this->Close();
                return 0;
            }
            if (SQLResult == SQL_SUCCESS)
            {
                BufLen = SQLLen;
            }
            else
            {
                BufLen = sizeof(SQLBinary);
            }
            lOfs += BufLen;
            memcpy(pSQLBuf, SQLBinary, BufLen);
            pSQLBuf = &pSQLBuf[lOfs];
        }
    }
    //SQLFreeHandle(SQL_HANDLE_STMT, this->m_hStmt);
    return BufLen;
}
void SQLCONNECT::SetAsBinary(LPTSTR lpszStatement, LPBYTE lpBinaryBuffer, SQLUINTEGER BinaryBufferSize)
{
    SQLINTEGER cbValueSize = -0x64 - BinaryBufferSize;
    SQLPOINTER pToken;
    BYTE cBUFFER[10000];
    SQLRETURN Result;
    SQLBindParameter(this->m_hStmt, 1, SQL_PARAM_INPUT,
        SQL_C_BINARY, SQL_LONGVARBINARY, BinaryBufferSize, 0, (SQLPOINTER)1, 0, &cbValueSize);
    SQLExecDirect(this->m_hStmt, (SQLTCHAR *)lpszStatement, SQL_NTS);
    Result = SQLParamData(this->m_hStmt, &pToken);
    int lOfs = 0;
    while (Result == SQL_NEED_DATA)
    {
        memcpy(cBUFFER, lpBinaryBuffer, sizeof(cBUFFER));
        Result = SQLPutData(this->m_hStmt, cBUFFER, BinaryBufferSize);
        Result = SQLParamData(this->m_hStmt, &pToken);
        lOfs += sizeof(cBUFFER);
    }
    SQLParamData(this->m_hStmt, &pToken);
    this->Close();
}
void SQLCONNECT::Disconnect()
{
    if (this->m_hStmt)
        SQLFreeHandle(SQL_HANDLE_STMT, this->m_hStmt);
    if (this->m_hConnection)
        SQLDisconnect(this->m_hConnection);
    if (this->m_hConnection)
        SQLFreeHandle(SQL_HANDLE_DBC, this->m_hConnection);
    this->m_hStmt = NULL;
    this->m_hConnection = NULL;
}
