Click here to Skip to main content
15,910,303 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Modeless Dialogs Pin
David Crow23-Jun-04 3:46
David Crow23-Jun-04 3:46 
Generaldetecting CDatabase disconnections Pin
craigiek23-Jun-04 1:18
craigiek23-Jun-04 1:18 
GeneralConvert from VS 6.0 project to VS .NET project Pin
anderslundsgard23-Jun-04 0:21
anderslundsgard23-Jun-04 0:21 
GeneralRe: Convert from VS 6.0 project to VS .NET project Pin
Anthony_Yio23-Jun-04 0:36
Anthony_Yio23-Jun-04 0:36 
GeneralRe: Convert from VS 6.0 project to VS .NET project Pin
anderslundsgard23-Jun-04 1:23
anderslundsgard23-Jun-04 1:23 
GeneralRe: Convert from VS 6.0 project to VS .NET project Pin
Anthony_Yio23-Jun-04 16:09
Anthony_Yio23-Jun-04 16:09 
GeneralRe: Convert from VS 6.0 project to VS .NET project Pin
anderslundsgard29-Jun-04 23:50
anderslundsgard29-Jun-04 23:50 
GeneralODBC and C++ Pin
SuzannaS23-Jun-04 0:09
SuzannaS23-Jun-04 0:09 
Hi,
I would like to connect do a DSN (data source name) through my code in C++, but I don't want to write the UserName and Password in my code: how can I do??

Here it is my code:

static bool IsSubscribed(SQLCHAR Account[], bool& subscription, bool& warning)
{
SQLHENV henv = NULL;
SQLHDBC hdbc = NULL;
SQLHSTMT hstmt = NULL;
SQLRETURN sRet;

PTSTR szDataSource = _T("DSN_NAME");
PTSTR szUID = _T("UserName");
PTSTR szPWD = _T("Password");

// Initialize the ODBC environment.
if (SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv) == SQL_ERROR)
{
WriteIntoFile("ERRORE Initialize the ODBC environment");
return false;
}

SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3,SQL_IS_INTEGER);

// Allocate a connection handle and connect to the data source.
if (SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc) == SQL_ERROR)
{
WriteIntoFile("ERRORE Allocate a connection handle");
return false;
}
if (SQLConnect(hdbc, (SQLTCHAR*) szDataSource, SQL_NTS,
(SQLTCHAR*) szUID, SQL_NTS, (SQLTCHAR*) szPWD, SQL_NTS) == SQL_ERROR)
{
WriteIntoFile("ERRORE Connect to the DataSource");
return false;
}

// Get a statement handle and execute a Transact-SQL SELECT statement
if (SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt) == SQL_ERROR)
{
WriteIntoFile("ERRORE Get a statement handle and execute a Trans-SQL");
return false;
}

SQLINTEGER cbAccount = SQL_NTS;

// ? marks the input parameter.
sRet = SQLPrepare(hstmt, (SQLCHAR*) "{call spIsSubscribed(?)}", SQL_NTS);

// Bind the input parameter.
sRet = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_CHAR, 20, 0, Account, 0, &cbAccount);

if( (SQLExecute(hstmt)) == SQL_ERROR)
{
WriteIntoFile("ERRORE Execute");
return false;
}

bool sub;
SQLINTEGER cbSub;

bool warn;
SQLINTEGER cbWarning;

// Retrieve data from row set.
SQLBindCol(hstmt, 1, SQL_C_BIT, (SQLPOINTER) &sub, 0, &cbSub);
SQLBindCol(hstmt, 2, SQL_C_BIT, (SQLPOINTER) &warn, 0, &cbWarning);

sRet = SQLFetch(hstmt);

if(sRet != SQL_SUCCESS && sRet != SQL_SUCCESS_WITH_INFO)
{
WriteIntoFile("ERRORE Fetch");
return false;
}

subscription = sub;
warning = warn;

/* Clean up.*/
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);

return true;

}

GeneralRe: ODBC and C++ Pin
Sumit Kapoor23-Jun-04 1:50
Sumit Kapoor23-Jun-04 1:50 
GeneralRe: ODBC and C++ Pin
basementman23-Jun-04 5:34
basementman23-Jun-04 5:34 
GeneralStrange problem with CString Pin
rrrado22-Jun-04 23:43
rrrado22-Jun-04 23:43 
GeneralRe: Strange problem with CString Pin
David Crow23-Jun-04 4:07
David Crow23-Jun-04 4:07 
GeneralRe: Strange problem with CString Pin
rrrado23-Jun-04 4:31
rrrado23-Jun-04 4:31 
GeneralRe: Strange problem with CString Pin
rrrado23-Jun-04 4:49
rrrado23-Jun-04 4:49 
GeneralRe: Strange problem with CString Pin
David Crow23-Jun-04 4:59
David Crow23-Jun-04 4:59 
GeneralRe: Strange problem with CString Pin
rrrado23-Jun-04 5:33
rrrado23-Jun-04 5:33 
GeneralRe: Strange problem with CString Pin
rrrado23-Jun-04 5:57
rrrado23-Jun-04 5:57 
GeneralRe: Strange problem with CString Pin
jmkhael23-Jun-04 6:58
jmkhael23-Jun-04 6:58 
GeneralRe: Strange problem with CString Pin
Ravi Bhavnani23-Jun-04 7:06
professionalRavi Bhavnani23-Jun-04 7:06 
GeneralRe: Strange problem with CString Pin
jmkhael23-Jun-04 7:08
jmkhael23-Jun-04 7:08 
GeneralRe: Strange problem with CString Pin
David Crow23-Jun-04 7:11
David Crow23-Jun-04 7:11 
GeneralRe: Strange problem with CString Pin
jmkhael23-Jun-04 7:13
jmkhael23-Jun-04 7:13 
GeneralRe: Strange problem with CString Pin
David Crow23-Jun-04 7:07
David Crow23-Jun-04 7:07 
GeneralRe: Strange problem with CString Pin
rrrado23-Jun-04 20:57
rrrado23-Jun-04 20:57 
GeneralC++ STL help... using pointer in STL map Pin
Indrawati22-Jun-04 23:36
Indrawati22-Jun-04 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.