[unixODBC-support] How to odbc.ini and odbcinst.ini -- or how to Server=??? in DSN-Less connect

Nick Gorham nick.gorham at easysoft.com
Tue Jun 3 00:39:59 BST 2008


Michael Higgins wrote:

>On Mon, 02 Jun 2008 17:48:47 +0100
>Nick Gorham <nick.gorham at easysoft.com> wrote:
>
>  
>
>>Michael Higgins wrote:
>>
>>    
>>
>>>Hello list --
>>>
>>>The problem I've had is that none of the DRIVER definitions seem to
>>>get picked up in SQLDriverConnect via perl-dbi.
>>>
>>>I use DBD::ODBC to connect. Using a defined DSN works, but I want a
>>>distributable app.
>>>
>>>      
>>>
>>It should work as long as the Driver= line in odbc.ini points to a 
>>driver in odbcinst.ini
>>
>>so in odbcinst.ini
>>
>>[MyDriver]
>>Driver = /path/to/my/driver.so
>>    
>>
>
>So, this should be okay:
>
>cat /etc/unixODBC/odbcinst.ini
>
>[Default]
>/usr/lib/libtdsodbc.so
>
>[FreeTDS]
>/usr/lib/libtdsodbc.so
>
>I want to call my driver FreeTDS.
>  
>

No, you need

[FreeTDS]
Driver = /usr/lib/libtdsodbc.so

>  
>
>>and in odbc,ini a entry that matches would be
>>
>>[MyDsn]
>>Driver = My Driver
>>
>>Then you could connect with
>>
>>DSN=MyDsn
>>    
>>
>
>Which I want to avoid, users needing a DSN entry. So, this file is not
>needed at all for my purpose, no?
>
>  
>
No.

>>or
>>
>>Driver={My Driver}
>>    
>>
>
>Which would require users have some... something (not DSN?) configured.
>
>(Why can't I just pass the path to the .so, I wonder?)
>
>  
>
I think you can, check the code in DriverManager/SQLDriverConnect.c, its 
some time simce I wrote it.

>>I don;t have a FreeTDS entry, but this is much the same and works
>>using the make test in the DBD module instalation
>>
>>odbcinst.ini
>>
>>[Easysoft ODBC-SQL Server]
>>Driver     = /usr/local/easysoft/sqlserver/lib/libessqlsrv.so
>>Setup       = /usr/local/easysoft/sqlserver/lib/libessqlsrvS.so
>>Threading       = 0
>>FileUsage       = 1
>>DontDLClose     = 1
>>UsageCount      = 1
>>    
>>
>
>Where are these last five options documented with the installation? Or
>are they specific to this other driver you use for example?
>  
>

FileUsage and UsageCount is documented in the MS docs, Threading and 
DontDLClose are documented in the unixODBC code, but normally are not 
needed. Look at the archives, you will see several copies of the 
comemnts in __handle.c that describes the setting.

>  
>
>>Values passed to perl
>>
>>DBI_DSN="dbi:ODBC:DRIVER={Easysoft ODBC-SQL 
>>Server};Server=192.168.250.71;Database=Test"
>>DBI_USER=test
>>DBI_PASS=test
>>
>>    
>>
>
>. . .
>
>Well, I went through this step-by-step. No joy, period. The only thing
>that works is having this:
>
>cat /etc/unixODBC/odbc.ini
>[Default]
>Driver          =  /usr/lib/libtdsodbc.so
>
>And NOT specifying the driver in my connect string. (Which seems
>totally in conflict with what you posted.)
>
>To illustrate:
>
># mv /etc/unixODBC/odbc.ini /etc/unixODBC/odbc.ini.bak
># mv /etc/unixODBC/odbcinst.ini /etc/unixODBC/odbcinst.ini.bak
># vim /etc/unixODBC/odbc.ini
># cat /etc/unixODBC/odbc.ini
>[Default]
>Driver          =  /usr/lib/libtdsodbc.so
>
>locate odbc |grep .ini
>cat /home/myuser/.odbc.ini
>[empty]
>
>And in my script:
>
>$DSN="Server=ip.add.of.svr;Port=1433;Database=thedb;UID=_user;PWD=_pass;";
>
>$DB->connect("dbi:ODBC:$DSN",'','', { AutoCommit
>=> 1, LongTruncOk=>1 }, { quote_char => '"',
>          name_sep => '.' }
>         );
>
>So, I'm stumped. I wasted many frustrated hours following all the
>how-tos and hints I found on the web, only to come upon this...
>solution(?) quite by trial-and-error.
>  
>
Thats working as you are not specifying a DSN= or a DRIVER=  in the 
connection string, so unixODBC is using the defaut section in odbc.ini. 
The best documention for this is the Microsoft one, as this is what I 
tried to make the driver manager copy word for word.

>Now what? Should we try to discover the root of the conflicting
>information, or should the unixODBC how-tos be updated, somehow? I was
>about to uninstall it completely when I found it works, but just not
>"as advertised". '-)
>  
>
Well, thats always a option, but remember, I am talking about what 
unixODBC does, and I showed it working how I believe it should with a 
driver that I know works in the same way, I can't say either way how 
another driver will operate, thats a question for the writers of that 
driver, but I believe, that the example I gave shows unixODBC is doing 
what it should in this situation, and given this is on the unixODBC 
support list, thats all I can talk about with any confidance.

-- 
Nick



More information about the unixODBC-support mailing list