On 08-Jan-2003 Jeff Urlwin wrote:
> Also...
> 
>> 
>> > > 
>> > > The only situation I've seen that can be a little 
>> confusing is this:
>> > > 
>> > > DBI->connect('dbi:ODBC:dsnname', 'dbuser', 'dbpass')
>> > > 
>> > > works
>> > > 
>> > > and
>> > > 
>> > > DBI->connect('dbi:ODBC:DSN=dsnname', 'dbuser', 'dbpass')
>> > > 
>> > > fails with whatever message the database engine returns 
>> for invalid
>> > > user/password (in MS SQL Server it is something to do with 
>> > NULL user).
>> > > 
>> > > First time I hit this it took a little head scratching to work out
>> > > what was going on. In the first case SQLConnect('dsnname', 
>> > 'dbuser',
>> > > 'dbpass') is called and as the database engine required a
>> > > username/password all was OK. In the second case 
>> > SQLDriverConnect(...,
>> > > "DSN=dsnname", ...) was called and I got the NULL user
>> > error. Adding
>> > > ";UID=dbuser;PWD=dbpass;" to the "DSN=dsnname" fixes the
>> > problem but
>> > > it can be a little confusing if you don't recognise the problem.
>> > > 
>> > > Perhaps a note about this in the docs might help.
>> > 
>> > Or better still, the DBD::ODBC driver could add
>> > ";UID=dbuser;PWD=dbpass;" to the $dsn automatically if it 
>> > sees that it matches /\bDSN=/.
>> 
>> Hmm...wouldn't it be better to add before all 
>> SQLDriverConnect actions if (defined($uid) && !($dsn =~ 
>> /UID=/)) ?? (and leaving DSN alone if we're going to call 
>> SQLConnect(), since that is second in the sequence...
>> 
>> I would think this would be safer than just checking for DSN=
> 
> Are UID and PWD consistent across all dbs?  I've tried this with DB2 and
> found it doesn't seem to like it.

As far as I am concerned UID and PWD are defined by ODBC (they are certainly in
my copy of the ODBC spec). In SQLDriverConnect:

"UID - A user ID"
"PWD - The password corresponding to the user ID, or an empty string if there
is no password for the user ID (PWD=;)"

Are you sure you are using the correct final connection string e.g.

DBI->Connect("dbi:ODBC:DSN=fred", "dbuser", "dbauth")
  needs to be:

SQLDriverConnect(..., "DSN=fred;UID=dbuser;PWD=dbauth;", ...)

I use this all the time with DB2. In fact, if you call SQLConnect("dsnname",
"dbuser", "dbauth") in the OOB client ODBC driver it translates it to
SQLDriverConnect("DSN=some_other_dsnname;UID=dbuser;PWD=dbauth;") before passing
it on to the real ODBC driver and I've never heard of this not working.

Martin
-- 
Martin J. Evans
Easysoft Ltd, UK
Development

Reply via email to