Fuism has asked for the wisdom of the Perl Monks concerning the following question:

I currently can connect to the SQL Server database using DBI and DBD:ODBC. It requires an id/password(the one Im using has only read access). The security group has created a group(Im in the group) and granting access to the group to access the database(using trusted connection).
Can I use DBI and DBD:ODBC to connect using a trusted connection? Whats the syntax or line(s) of code I need ot use? Any help would be greatly appreciated.
Thanks in advance, Fuism
  • Comment on Using Perl to connect using trusted connection

Replies are listed 'Best First'.
Re: Using Perl to connect using trusted connection
by Ven'Tatsu (Deacon) on Sep 13, 2004 at 20:10 UTC
    Include Trusted_Connection=yes in your DSN.
    my $DSN = "driver={SQL Server};Server=$server;database=$database;Trust +ed_Connection=yes"; my $dbh = DBI->connect("dbi:ODBC:$DSN") || die "Error: $DBI::errstr";
      Thanks guys for all your help. I solved the problem. Here's the code of my connection:
      $dbprod = DBI->connect('dbi:ODBC:PROD2', $user, $pass, { RaiseError => + 1, odbc_cursortype => 2}); PROD2 is a "System DSN" set up through using the Windows "ODBC Data So +urce Administrator" clicking on the "With windows NT authentication.. +." Instead of "With SQL Server authentication..."
      I it wouldnt work unless I used my NT login and password for $user and $pass. Once again thanks for all your help, your clue made me think more about the problem..... -Fuism
      This works PERFECT Thanks a lot!!! I mean this code :) Include Trusted_Connection=yes in your DSN.
      my $DSN = "driver={SQL Server};Server=$server;database=$database;Trust + +ed_Connection=yes"; my $dbh = DBI->connect("dbi:ODBC:$DSN") || die +"Error: $DBI::errstr";
Re: Using Perl to connect using trusted connection
by joecamel (Hermit) on Sep 13, 2004 at 19:04 UTC
    1) Use odbcad to create a system DSN. At the end of the wizard, click "Test Connection" to make sure it's set up properly.

    2) Specify the username and password in the DBI connect() call.

    my $dbh = DBI->connect("dbi:ODBC:$dsnname", $username, $password);
    joecamel
Re: Using Perl to connect using trusted connection
by doowah2004 (Monk) on Sep 13, 2004 at 17:03 UTC
    I have not tried to do this, and the code that I am posting I read somewhere and is untested. With that said, try:
    my $dbh = DBI->connect('dbi:ODBC:Test',undef,undef, { RaiseError => 1 + });


    Hope that this helps, Cameron
      Cameron, yea I already tried that, it doesnt work. (Error basically state "DBI Connect('TEST,'',... failed: at line 33" I got this same thing from the DBI docs and also an email post on the web. Thanks for the input.. Paofue