Re: Username and password in odbc.ini instead of command line

"James K. Lowden" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
On Wed, 18 Jan 2012 16:53:06 -0500
Ruiyuan Jiang <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.