NewConnection in TDAConnectionManager problem (Delphi)?

I made sample applications (server and client) by ‘MultiDB Login Server’ wizard (Data abstract trial 6.0.61.1029) in Delphi 7. Server application should connect database in ‘SQL Server’ with UniDAC driver (version 4.3.8 - newest version). These applications was upgrade to Delphi XE2. Before I upgrade applications to Delphi XE2 I put uDAUniDACDriver.pas unit in uses clause of fServerDatModule (this unit contain ConnectionManager and DriverManager).

I want to check username and password from ‘SQL Server’.

Unit LoginService_Impl.pas contain event OnLogin:

procedure TLoginService.LoginServiceLogin(Sender: TObject; aUserID,
aPassword: Utf8String; aConnectionName: Utf8String; out aUserInfo: UserInfo;
var aLoginSuccessful: Boolean);

var
aIDAConnection : IDAConnection;

begin
aIDAConnection := Self.ConnectionManager.NewConnection(aConnectionName, True, aUserID, aPassword);
aLoginSuccessful := aIDAConnection.Connected;

if aLoginSuccessful then begin
aUserInfo := UserInfo.Create;
aUserInfo.SessionID := UTF8String(GuidToAnsiString(ClientID));
aUserInfo.UserID := aUserID;

Session['UserID'] := aUserID;

// store connection name for use in data service
Session['ConnectionName'] := aConnectionName;

end
else begin
DestroySession;
end;
end;

Connection aConnectionName (has valid ConnectionString) is in the Self.ConnectionManager (Self.ConnectionManager = ServerDataModule.ConnectionManager).

I try to check username and password: aUserID = ‘10’ and aPassword = ‘20’ (wrong UserID and Password) for the database in the connection string, but aIDAConnection.Connected return True.

When NewConnection is executed with aConnectionName (aConnectionName is in ConnectionManager pool) event ‘OnConnectionCreated’ is fired?

ConnectionManager properties:
MaxPoolSize = 10
PoolBehaviour = pbWait
PoolingEnabled = True
PoolTimeoutSeconds = 60
PoolTransactionBehaviour = ptNone
WaitIntervalSeconds = 1

ConnectionManager contain one connection.

Maybe I doing something wrong.

Best Regards,

Goran

Hello Goran,

I could assume that this situation takes place if you first connect successfully to DB and then try to connect with another credentials. In this case connection manager just finds connection in connection pool, compares connection string from schema modeler for connection that you are trying to open and connection from the pool, but not applies given userID and Password to connection string. Thanks for the report, the issue was logged as #57336.

As a workaround you could either disable connection pool - set TDAConnectionManager.PoolingEnabled:=False;
or do the following fix in uDAClasses.pas:

function TDAConnectionManager.NewConnection(const aConnectionName: string;
OpenConnection: boolean = TRUE; const UserID: string = ‘’; const Password: string = ‘’): IDAConnection;

begin
try
// If pooling is not enable immediately creates a connection.
// This is the quickest way to Acquire one
if not fPoolingEnabled then begin

else

for i := 0 to list.Count -1 do begin
tempconn := TCachedConnection(list[i]);

     if SameText(tempconn.Connection.ConnectionString, conn.ConnectionString) and
           SameText(tempconn.Connection.ConnectionType, conn.ConnectionType) then begin

         /////// REMOVED
         // list.Delete(i);
         Result := tempconn.Connection;

         /////ADDED
         if (UserID<>'') and (Password<>'') and
            (result.UserID=UserID) and (Result.Password=Password) then begin

            list.Delete(i);
            tempconn.Free;
            if Assigned(fOnConnectionAcquired) then fOnConnectionAcquired(Self, result);
            break; { for}
            //              Exit;
         end
         else Result:=nil;

       /// ADDED

     end;
  end;
 if Result = nil then begin
        // If it doesn't find one and the max poolsize is not reached then creates it...
     ....

end;

Hope this helps

I tried to set
TDAConnectionManager.PoolingEnabled:=False;
but it doesn’t work.

I also try to make new connection (using TDAConnectionCollection.Add) (to same database in SQL Server) in connection manager (with unique name using method TSearcheableCollection.FindUniqueName) in OnLogin event (in unit LoginService_Impl.pas) with wrong username and password (in ConnectionString), but aIDAConnection.Connected return True (successful connection to database in SQL Server).

I have trial version of Data Abstract (version 6.0.61.1029). I use UniDAC professional (version 4.3.8) (http://www.devart.com/unidac/) for connection from middle-tier server to database (in SQL Server). Maybe, these versions of Data Abstract and UniDAC can not work together.

Maybe I found a solution. Default connection string for
Driver Name: UniDAC
and
AuxDriver: SQL Server

contain 'custom driver-dependent parameters’
Parameters: Schemas=1;Integrated Security=SSPI

Integrated Security=SSPI is Windows Authentication (Username, Password and database in connection string are ignored). It uses username and password from windows login.
When connection string does not contain ‘Integrated Security=SSPI’ this is ‘SQL Authentication’.

I have one virtual machine with client and server applications and second with ‘SQL Server’. Both virtual machine have same windows login.

Without ‘Integrated Security=SSPI’ in connection string, client login works as expected.

Disabling connection pool:
TDAConnectionManager.PoolingEnabled:=False;
works.

It works.

Thank you for help.