Skip to Content.
Sympa Menu

freetds - Re: [freetds] Username and password in odbc.ini instead of command line

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "James K. Lowden" <jklowden AT freetds.org>
  • To: freetds AT lists.ibiblio.org
  • Subject: Re: [freetds] Username and password in odbc.ini instead of command line
  • Date: Wed, 18 Jan 2012 18:19:07 -0500

On Wed, 18 Jan 2012 16:53:06 -0500
Ruiyuan Jiang <Ruiyuan_Jiang AT liz.com> wrote:

> Since we will access MSSQL server through application, there is a
> request that whether I can put the username and password into
> odbc.ini instead of part of 'isql' command line. I appended
> "username=xxx" and "password=xxx" in the odbc.ini.
>
> $ isql -v MSSQLSERVER
> [S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
...
> I have tried to use "user", "uid" and "userid" instead of
"username"
> in the odbc.ini but no luck.

http://www.freetds.org/userguide/odbcconnattr.htm

The FreeTDS ODBC driver does not read user credentials from odbc.ini.

Besides the obvious security issue, things like UID and PWD don't
belong in odbc.ini because they don't describe the server or the
connection. Only one of many potential users could be the "DSN user".
Not much upside potential there.

What to do?

Best is to use Kerberos.

Second-best is to keep the username and password in a file, and
read that at runtime. For example, some ftp clients define a file
${HOME}/.netrc that must have 0600 permissions. Each line has the form

machine M login U password P

where U and P are the username and password for machine M.

You can use such a file to get the password without echoing it to the
log like this:

$ bsqlodbc -S $S -U $U
-P $(awk "/^machine.*$S/ {print \$6}" {$HOME}/.netrc)

It's a neater if that awk bit is in a little script

$ bsqlodbc -S $S -U $U -P $(password $S $U)

HTH.

--jkl





Archive powered by MHonArc 2.6.24.

Top of Page