cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SQL Anywhere on Linux

oneeyeman1
Participant
0 Likes
16

Hi, ALL,

I have installed SQL Anywhere 17 full on my Windows box.

 

Now yesterday I downloaded the SQL Anywhere client on one of my Linux boxes and successfully installed it.

I already have unixODBC set up on that box and so I tried to set up a connection and then tried to run my program.

 

I used 64 bit driver as my program is compiled as 64 bit.

 

Unfortunately the program crashed inside SQLAllocHandle() call of the driver.

 

I will not have access to this machine until Friday, but does this looks familiar to anybody?

How do I set up the unixODBC with SQLAnywhere to get a successful connection?

 

I read the docs and gather that the server comes with its own Driver Manager implementation, but I'm using only the client.

 

Thank you.

 

P.S.: This is the code I'm using:

 

[code]

int ODBCDatabase::Connect(const std::wstring &selectedDSN, std::vector<std::wstring> &dbList, std::vector<std::wstring> &errorMsg)
{
int result = 0, bufferSize = 1024;
std::vector<SQLWCHAR *> errorMessage;
SQLWCHAR connectStrIn[sizeof(SQLWCHAR) * 255], driver[1024], dsn[1024], dbType[1024];
SQLSMALLINT OutConnStrLen;
SQLRETURN ret;
SQLUSMALLINT options;
SQLWCHAR *user = nullptr, *password = nullptr;
SQLWCHAR driverName[1024];
SQLWCHAR dbName[1024];
SQLWCHAR userName[1024];
std::wstring connectingDSN, connectingUser = L"", connectingPassword = L"";
pimpl.m_type = L"ODBC";
pimpl.m_pgLogFile = L"";
if( !odbc_pimpl )
odbc_pimpl = new ODBCImpl;
std::wstring::size_type pos = selectedDSN.find( L';' );
if( pos == std::wstring::npos )
connectingDSN = selectedDSN;
else
{
std::wstring temp = selectedDSN.substr( selectedDSN.find( L"DSN=" ) + 4 );
connectingDSN = temp.substr( 0, temp.find( L";") );
// connectingDSN = selectedDSN.substr( 0, pos );
temp = temp.substr( temp.find( L"UID=" ) + 4 );
connectingUser = temp.substr( 0, temp.find( L";" ) );
temp = temp.substr( temp.find( L"PWD=" ) + 4 );
connectingPassword = temp.substr( 0, temp.find( L";" ) );
user = new SQLWCHAR[connectingUser.length() + 2];
password = new SQLWCHAR[connectingPassword.length() + 2];
memset( user, '\0', connectingUser.length() + 2 );
memset( password, '\0', connectingPassword.length() + 2 );
uc_to_str_cpy( user, connectingUser );
uc_to_str_cpy( password, connectingPassword );
}
m_connectString = new SQLWCHAR[sizeof(SQLWCHAR) * 1024];
memset( dsn, 0, sizeof( dsn ) );
memset( connectStrIn, 0, sizeof( connectStrIn ) );
memset( driver, 0, sizeof( driver ) );
uc_to_str_cpy( dsn, connectingDSN.c_str() );
ret = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HENV, &m_env );
if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
{
errorMsg.push_back( L"Failed to allocate memory for the connection" );
return 1;
}
ret = SQLSetEnvAttr( m_env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER );
if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
{
GetErrorMessage( errorMsg, ENV_ERROR );
result = 1;
}
else
{
ret = SQLAllocHandle( SQL_HANDLE_DBC, m_env, &m_hdbc );
if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO )
{
GetErrorMessage( errorMsg, ENV_ERROR );
return 1;
}
else
{
if( !GetDriverForDSN( dsn, driver, errorMsg ) )
{
std::unique_ptr<SQLWCHAR[]> tempPostgres( new SQLWCHAR[13] );
memset( tempPostgres.get(), '\0', 13 );
uc_to_str_cpy( tempPostgres.get(), L"PostgreSQL " );
if( connectStrIn[0] == '\0' )
{
uc_to_str_cpy( connectStrIn, L"DSN=" );
uc_to_str_cpy( connectStrIn, connectingDSN.c_str() );
}
if( equal( tempPostgres.get(), driver ) )
uc_to_str_cpy( connectStrIn, L";UseServerSidePrepare=1;ShowSystemTables=1;" );
std::wstring tempmySQL;
str_to_uc_cpy( tempmySQL, driver );
if( tempmySQL.find( L"myodbc" ) != std::wstring::npos )
uc_to_str_cpy( connectStrIn, L";NO_SCHEMA=0;NO_CATALOG=0" );
if( user && password )
{
uc_to_str_cpy( connectStrIn, L";UID=" );
copy_uc_to_uc( connectStrIn, user );
uc_to_str_cpy( connectStrIn, L";PWD=" );
copy_uc_to_uc( connectStrIn, password );
}
delete[] user;
user = nullptr;
delete[] password;
password = nullptr;
ret = SQLSetConnectAttr( m_hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)50, 0 );
if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA )
{
GetErrorMessage( errorMsg, 2 );
result = 1;
}
if( !result )
{
#ifdef _WIN32
options = m_ask ? SQL_DRIVER_COMPLETE : SQL_DRIVER_NOPROMPT;
#else
options = SQL_DRIVER_NOPROMPT;
#endif
ret = SQLDriverConnect( m_hdbc, m_handle, connectStrIn, SQL_NTS, m_connectString, 1024, &OutConnStrLen, options );
if( ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO && ret != SQL_NO_DATA )
{
GetErrorMessage( errorMsg, CONN_ERROR );
result = 1;
}
if( ret == SQL_NO_DATA )
{
errorMsg.push_back( L"Connection cancelled" );
return 0;
}
}

[/code]

Accepted Solutions (0)

Answers (0)