bool bIsSQLServerAvailable()
{
HENV henv;
HDBC hdbc;
RETCODE retcode;
BOOL bResult = FALSE;
retcode = SQLAllocEnv(&henv); /* Environment handle */
if (retcode == SQL_SUCCESS)
{
retcode = SQLAllocConnect(henv, &hdbc); /* Connection handle */
if (retcode == SQL_SUCCESS)
{
/* Set login timeout to 5 seconds. */
SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 5);
/* Connect to data source */
retcode = SQLConnect(hdbc, (unsigned char *)m_csDSN), SQL_NTS,
(unsigned char *)m_sSQLServerUID, SQL_NTS,
(unsigned char *)m_sSQLServerPWD, SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
bResult = TRUE;
}
SQLFreeConnect(hdbc);
ASSERT ( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO);
}
SQLFreeEnv(henv);
ASSERT ( retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO);
}
return bResult;
}
UINT CCMCashDrawer::GetSearchResultFromBackup( LPVOID lpvd)
{
//#define LEN 50
char *DSN = m_sSQLServerDSN;
char *UID = m_sSQLServerUID;
char *PWD = m_sSQLServerPWD;
HENV henv;
HDBC hdbc;
HSTMT hstmt;
RETCODE retcode;
char *csSQLstmt = "select CUSTACCTNO, BLGNUMBER, BLGNUMTYPE, CUSTACCTSTAT, CNALINE1, CNALINE2, RUNGBALDUEAMT from _table ";
retcode = SQLAllocEnv(&henv); /* Environment handle */
if (retcode == SQL_SUCCESS)
{
retcode = SQLAllocConnect(henv, &hdbc); /* Connection handle */
if (retcode == SQL_SUCCESS)
{
/* Set login timeout to 5 seconds. */
SQLSetConnectOption(hdbc, SQL_LOGIN_TIMEOUT, 5);
/* Connect to data source */
retcode = SQLConnect(hdbc,
(unsigned char *)m_csDSN), SQL_NTS,
(UCHAR FAR *)UID, SQL_NTS,
(UCHAR FAR *)PWD, SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
/* Process data after successful connection */
retcode = SQLAllocStmt(hdbc, &hstmt); /* Statement handle */
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect(hstmt, (unsigned char *)(csSQLstmt), SQL_NTS);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
while (TRUE)
{
retcode = SQLFetch(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
char [128] cBN;
SDWORD nLen;
static SQLCHAR szCAN[LEN_CAN], szBN[LEN_BN], szBNT[LEN_BILLING_NO_TYPE], szSTAT[LEN_CUST_ACCOUNT_STAT], szCNA1[LEN_CM_CNALINE1], szCNA2[LEN_CM_CNALINE2];
static SQLCHAR szBalance[LEN_RUNNING_BALANCE_DUE];
SQLGetData(hstmt, 1, SQL_C_CHAR, szCAN, LEN_CAN + 1, &nLen);
SQLGetData(hstmt, 2, SQL_C_CHAR, szBN, LEN_BN + 1, &nLen);
strcpy(cBN,szBN);
//cBN.TrimRight();
SQLGetData(hstmt, 3, SQL_C_CHAR, szBNT, LEN_BILLING_NO_TYPE + 1, &nLen);
SQLGetData(hstmt, 4, SQL_C_CHAR, szSTAT, LEN_CUST_ACCOUNT_STAT + 1, &nLen);
SQLGetData(hstmt, 5, SQL_C_CHAR, szCNA1, LEN_CM_CNALINE1 + 1, &nLen);
SQLGetData(hstmt, 6, SQL_C_CHAR, szCNA2, LEN_CM_CNALINE2 + 1, &nLen);
SQLGetData(hstmt, 7, SQL_C_CHAR, szBalance, LEN_RUNNING_BALANCE_DUE + 1,&nLen);
CCMCustomer* pNewCCMCustomer = new CCMCustomer;
// copy tran data to new Customer object
pNewCCMCustomer->SetCAN(szCAN);
pNewCCMCustomer->SetBillingNo(cBN);
pNewCCMCustomer->SetBillingNoType(szBNT);
pNewCCMCustomer->SetAccountStat(szSTAT);
pNewCCMCustomer->SetCNALine1(szCNA1);
pNewCCMCustomer->SetCNALine2(szCNA2);
strcpy( sBalance, szBalance);
CAppCurrency cy = CAppCurrency(_atoi64(sBalance.Left(LEN_RUNNING_BALANCE_DUE-3)),atol(sBalance.Mid(13,3))*10 );
cy.Round(2);
pNewCCMCustomer->SetRunningBalanceDue(cy);
// end copy
AddTail(pNewCCMCustomer);
}
else
{
break;
}
}
}
retcode = SQLFreeStmt(hstmt, SQL_DROP);
}
SQLDisconnect(hdbc);
}
SQLFreeConnect(hdbc);
}
SQLFreeEnv(henv);
}
if (retcode != SQL_SUCCESS {
LOGEVENT(EVENTLOG_ERROR_TYPE,
" GetSearchResultFromBackup - FAILED"
);
}
return 0;
}