Re: Connection failed [was: Re: Distribution package for OSX] - Mailing list pgsql-odbc

From Igor Korot
Subject Re: Connection failed [was: Re: Distribution package for OSX]
Date
Msg-id CA+FnnTzLG7BXpehKSZDUExwQ0RhWQR28szaXE_7z_Lt=GGhvqA@mail.gmail.com
Whole thread Raw
In response to Re: Connection failed [was: Re: Distribution package for OSX]  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-odbc
Adrian et al,

On Wed, Dec 7, 2016 at 12:15 AM, Adrian Klaver
<adrian.klaver@aklaver.com> wrote:
> On 12/06/2016 08:48 PM, Igor Korot wrote:
>>
>> Hi, guys,
>> So I moved a little further with this.
>>
>> First of all I found out that default OSX install comes with client tools
>> pre-installed. No server.
>>
>> So I installed the PostgreSQL server on my Mac.
>>
>> Next is trying to connect with iODBC.
>>
>> But first I tried to open SQL Shell (psql). Here is the session log:
>>
>> [code]
>> Last login: Tue Dec  6 23:11:08 on ttys001
>> /Library/PostgreSQL/9.1/scripts/runpsql.sh; exit
>> Igors-MacBook-Air:~ igorkorot$ /Library/PostgreSQL/9.1/scripts/runpsql.sh;
>> exit
>> Server [localhost]:
>> Database [postgres]:
>> Port [5432]:
>> Username [postgres]:
>> Password for user postgres:
>> psql (9.1.24)
>> Type "help" for help.
>>
>> postgres=# \q
>> logout
>>
>> [Process completed]
>> [/code]
>>
>> So I presume that the server is running.
>>
>> Next I tried to configure ODBC. Since there is no psqlODBCS.so to
>> setup the connection,
>> I tried to do it manually.
>>
>> Here are the files:
>>
>> [code]
>> Igors-MacBook-Air:~ igorkorot$ cat .odbcinst.ini
>> [ODBC Drivers]
>> MySQL ODBC 5.3 Unicode Driver = Installed
>> MySQL ODBC 5.3 ANSI Driver    = Installed
>> PostgreSQL Unicode Driver     = Installed
>>
>> [ODBC Connection Pooling]
>> PerfMon    = 0
>> Retry Wait =
>>
>> [MySQL ODBC 5.3 Unicode Driver]
>> Driver = /usr/local/lib/libmyodbc5w.so
>>
>> [MySQL ODBC 5.3 ANSI Driver]
>> Driver = /usr/local/lib/libmyodbc5a.so
>>
>> [PostgreSQL Unicode Driver]
>> Driver = /usr/local/lib/psqlodbcw.so
>>
>> Igors-MacBook-Air:~ igorkorot$ cat .odbc.ini
>> [ODBC Data Sources]
>> myodbc  = MySQL ODBC 5.3 Unicode Driver
>> myodbca = MySQL ODBC 5.3 ANSI Driver
>> postgre = PostgreSQL Unicode Driver
>>
>> [ODBC]
>> Trace         = 0
>> TraceAutoStop = 0
>> TraceFile     =
>> TraceLibrary  =
>>
>> [myodbc]
>> Driver = MySQL ODBC 5.3 Unicode Driver
>> SERVER = localhost
>> PORT   = 3306
>>
>> [myodbca]
>> Driver = MySQL ODBC 5.3 ANSI Driver
>> SERVER = localhost
>> PORT   = 3306
>>
>> [postgre]
>> Driver   = PostgreSQL Unicode Driver
>> SERVER   = localhost
>> PORT     = 5432
>> User     = postgres
>> Password = wasqra
>> Database = postgres
>> [/code]
>
>
> If I am following this:
>
>
http://www.iodbc.org/dataspace/doc/iodbc/wiki/iodbcWiki/FAQ#What%27s%20an%20odbc.ini%20and%20what%20do%20I%20put%20in%20it%3F
>
> then should it not be:
>
> [postgre]
> Driver   = /usr/local/lib/psqlodbcw.so
> host     = localhost
> SERVER   = localhost
> ServerName = localhost
> PORT     = 5432
> UserName = postgres
> Password = wasqra
> Database = postgres

Will try that tonight.

>
>>
>> Please tell me if I made a mistake configuring the DSN.
>>
>> Now when trying to connect to the database I'm getting following error:
>
>
> How did you connect?

Here is my code:

[code]
void ODBCDatabase::uc_to_str_cpy(SQLWCHAR *dest, const std::wstring &src)
{
const wchar_t *temp = src.c_str();
while( *dest )
{
*dest++;
}
while( *temp )
{
*dest = *temp;
*dest++;
*temp++;
}
*dest++ = 0;
*dest = 0;
}

int ODBCDatabase::Connect(std::wstring selectedDSN,
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;
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, selectedDSN.c_str() );
ret = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HENV, &m_env );
if( ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO )
{
ret = SQLSetEnvAttr( m_env, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)
SQL_OV_ODBC3, SQL_IS_INTEGER );
if( ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO )
{
ret = SQLAllocHandle( SQL_HANDLE_DBC, m_env, &m_hdbc );
if( ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO )
{
if( !GetDriverForDSN( dsn, driver, errorMsg ) )
{
uc_to_str_cpy( connectStrIn, L"DSN=" );
uc_to_str_cpy( connectStrIn, selectedDSN.c_str() );
uc_to_str_cpy( connectStrIn, L";Driver=" );
copy_uc_to_uc( connectStrIn, driver );
SQLSetConnectAttr( m_hdbc, SQL_LOGIN_TIMEOUT, (SQLPOINTER)5, 0 );
options = m_ask ? SQL_DRIVER_COMPLETE_REQUIRED : SQL_DRIVER_COMPLETE;
ret = SQLDriverConnect( m_hdbc, m_handle, connectStrIn, SQL_NTS,
m_connectString, 1024, &OutConnStrLen, options );
// More code dealing with errors or successful connection.
}
[/code]

The code above correctly works on Windows and unixODBC connecting to
the MySQL server.

Thank you.

>
>>
>> [quote]
>> Could not connect to server. No such file or directory.
>> [/quote]
>>
>> Also, just for the reference, here is the files in /usr/local/lib:
>>
>> [code]
>> Igors-MacBook-Air:~ igorkorot$ ls -la /usr/local/lib/
>> total 27152
>> drwxr-xr-x  14 root  wheel      476 Dec  3 10:45 .
>> drwxrwxr-x   9 root  wheel      306 Jun  4  2016 ..
>> -rwxr-xr-x   1 root  wheel   367404 Jan 12  2016
>> libcppunit-1.12.1.0.0.dylib
>> lrwxr-xr-x   1 root  wheel       27 Jan 12  2016
>> libcppunit-1.12.1.dylib -> libcppunit-1.12.1.0.0.dylib
>> -rw-r--r--   1 root  wheel  3740688 Jan 12  2016 libcppunit.a
>> lrwxr-xr-x   1 root  wheel       27 Jan 12  2016 libcppunit.dylib ->
>> libcppunit-1.12.1.0.0.dylib
>> -rwxr-xr-x   1 root  wheel      860 Jan 12  2016 libcppunit.la
>> -rwxr-xr-x   1 root  wheel  4604056 Jun 18  2014 libmyodbc5a.so
>> -rwxr-xr-x   1 root  wheel  4600096 Jun 18  2014 libmyodbc5w.so
>> drwxr-xr-x   3 root  wheel      102 Jan 12  2016 pkgconfig
>> -rwxr-xr-x   1 root  wheel      945 Dec  3 10:45 psqlodbcw.la
>> -rwxr-xr-x   1 root  wheel   555716 Dec  3 10:45 psqlodbcw.so
>> lrwxr-xr-x   1 root  wheel       16 Jan 31  2016 wxPython ->
>> wxPython-3.0.2.0
>> drwxr-xr-x   6 root  wheel      204 Nov 27  2014 wxPython-3.0.2.0
>> [/code]
>>
>> Could anyone spot an error?
>> Or maybe I have to have a non-default database in order to connect via
>> ODBC?
>>
>> Thank you.
>>
>> P.S.: Hopefully the mailer will understand that there is a
>> continuation of the old thread...
>>
>> On Sat, Dec 3, 2016 at 2:30 PM, Adrian Klaver <adrian.klaver@aklaver.com>
>> wrote:
>>>
>>> On 12/03/2016 11:00 AM, Igor Korot wrote:
>>>>
>>>>
>>>> Adrian,
>>>
>>>
>>>
>>>>
>>>> Thank you.
>>>>
>>>> BTW, is there a setup library generated? Maybe that the reason the
>>>> driver
>>>> is
>>>> not in the list?
>>>>
>>>>>
>>>
>>> To add:
>>>
>>> http://www.iodbc.org/dataspace/doc/iodbc/wiki/iodbcWiki/ODBCOnUnix
>>>
>>>
>>> --
>>> Adrian Klaver
>>> adrian.klaver@aklaver.com
>>
>>
>
>
> --
> Adrian Klaver
> adrian.klaver@aklaver.com


pgsql-odbc by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Connection failed [was: Re: Distribution package for OSX]
Next
From: Igor Korot
Date:
Subject: Re: Connection failed [was: Re: Distribution package for OSX]