Using SSPI with SQL Server

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Licences AAW
Posts: 10
Joined: Tue 21 Jul 2015 07:43

Using SSPI with SQL Server

Post by Licences AAW » Tue 21 Jul 2015 07:53

Hi,

I'm facing an issue while trying to connect to a SQL Server with SSPI integrated security.

If my connection string uses "Integrated Security=SSPI", it is accepted by TUniConnection but seems not have any effect.
If my connection string uses "Authentication=Windows", it is refused by TUniConnection as "Authentication" is not a valid parameter name

Of course, if I set manually the specfic option "Authentication" = "auWindows", it works well but my goal is to control ALL connection parameters with the connection string.

My question is: did I do something wrong (some trick I missed somewhere) or is there a problem in UniDac 6.1.5 ?

(In next post, a sample app which shows the problem)

Licences AAW
Posts: 10
Joined: Tue 21 Jul 2015 07:43

Re: Using SSPI with SQL Server

Post by Licences AAW » Tue 21 Jul 2015 08:01

Code: Select all

uses
  System.SysUtils, uni, SQLServerUniProvider, ActiveX;

const
  ConnectionStr = 'Provider Name=SQL Server;Data Source=XXXXX';

var
  connection: TUniConnection;
begin
  try
    CoInitialize(nil);
    connection := TUniConnection.Create(nil);
    try
      connection.LoginPrompt := False;
      try
        connection.ConnectString := ConnectionStr + ';Integrated Security=SSPI';
        connection.Connect;
        writeln('SSPI: connected');
      except
        writeln('SSPI: not connected = ' + Exception(ExceptObject).Message);
      end;

      try
        connection.ConnectString := ConnectionStr + ';Authentication=Windows';
        connection.Connect;
        writeln('Authentication: connected');
      except
        writeln('Authentication: not connected = ' + Exception(ExceptObject).Message);
      end;

      try
        connection.ConnectString := ConnectionStr + ';Integrated Security=SSPI';
        connection.SpecificOptions.Values['SQL Server.Authentication'] := 'auWindows';
        connection.Connect;
        writeln('SSPI+Authentication: connected');
      except
        writeln('SSPI+Authentication: not connected = ' + Exception(ExceptObject).Message);
      end;
    finally
      connection.Free;
      CoUninitialize;
    end;

    readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.
and here is the result it produce:

Code: Select all

SSPI: not connected = Login failed for user 'sa'.
Authentication: not connected = Connection parameter name is unknown: Authentication
SSPI+Authentication: connected

azyk
Devart Team
Posts: 1119
Joined: Fri 11 Apr 2014 11:47
Location: Alpha Centauri A

Re: Using SSPI with SQL Server

Post by azyk » Mon 27 Jul 2015 11:05

Thank you for the information. We have reproduced this problem and are investigating it. We will notify you about the results as any are available.

Post Reply