ankushj10 wrote:
> --- In c-prog@yahoogroups.com, Thomas Hruska <[EMAIL PROTECTED]> wrote:
>> ankushj10 wrote:
>>> hi all,
>>>
>>> i m trying to connect to MySQL database in VC++.net using SDK.
>>>
>>> i m getting error while executing-
>>>
>>>
>>> SQLExecDirect(SQLHSTMT     StatementHandle,
>>>      SQLCHAR *     StatementText,
>>>      SQLINTEGER     TextLength);
>>>
>>>
>>> Please help me.
>>>
>>> bye
>>> Ankush Jain.
>> That's not very descriptive of the problem.  Show source code and 
> the 
>> error code from the function/compiler error.  Also, keep in mind 
> you 
>> need to install MyODBC to get the ODBC APIs to work with MySQL.
>>
>> -- 
>> Thomas Hruska
>> CubicleSoft President
>> Ph: 517-803-4197
>>
>> *NEW* MyTaskFocus 1.1
>> Get on task.  Stay on task.
>>
>> http://www.CubicleSoft.com/MyTaskFocus/
>>
> 
> 
> code is too long, i m sending the function call.
> 
> Database connection via SDK(VC++'s APIs) requires to 1st connect it, 
> then execute query and finally fetch records. i m able to connect it 
> successfully using-
> 
>     ----- start VC code  --------
> retcode = SQLAllocHandle(SQL_HANDLE_DBC, m_henv, phdbc);
> 
> m_dwLastErrorCode = GetLastError();
> if(retcode != SQL_SUCCESS)
>       return RETCODE_FAILURE; 
> 
> SQLSetConnectOption(*phdbc, SQL_LOGIN_TIMEOUT, 20);
> 
> SQLSetEnvAttr(*phdbc, SQL_ATTR_ODBC_VERSION,(SQLPOINTER)SQL_OV_ODBC3, 
> SQL_IS_INTEGER);
> 
> SQLDriverConnect(*phdbc,  
>                   0,                                  
>                   (SQLWCHAR*)ConnStrIn,                       
>                   SQL_NTS,                            
>                   ConnStrOut,                 
>                   LINESIZE,                           
>                   &cbConnStrOut,              
>                   SQL_DRIVER_NOPROMPT);
> 
>     ----- end VC code  --------
> 
> 
> but my stmt-
> 
>     ----- start VC code  --------
> SQLExecDirect(*phstmt, (SQLWCHAR*)"select 
> CallId,Category,Section,Vote from callervoting", SQL_NTS);
>     ----- end VC code  --------
> 
> is giving error    SQL_ERROR. i m not able to figure out whats the 
> actual error.

You are typecasting to Unicode.  That won't work.  Use _T("Text goes 
here") if you have it or L"Text goes here" or turn off Unicode builds. 
You probably threw in the (SQLWCHAR *) cast to get rid of a compiler 
_error_.  Errors in function calls mean you did something wrong and a 
typecast is almost always the wrong solution for the problem.

I don't see the SQLAllocHandle() call that creates m_henv, but I assume 
you create that elsewhere.  As far as I can tell, you aren't checking 
any calls for failure prior to the SQLExecDirect() call (but you might 
have stripped that out for readability).  If the Unicode cast in the 
SQLExecDirect() call is any indicator, the similar cast in 
SQLDriverConnect() should be causing that function to fail as well.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to