开发者

How is ConnectionString used when connecting to AD using ADsDSOObject?

I recently took over some Delphi code (This is Delphi 5, but I don't think that's important) which queries AD using LDAP. The code is quite confusing, because it containst both ConnectionString and directly set properties. There's an installation program, where a number of AD parameters are entered. Which parts of the code are relevant, and which parts can I cut? I'm particularly interested if there are unnecessary questions in the installation program.

  • Is it possible to simplify the code? (i.e. does ConnectionString (or any of the containing parameters) have any use in this code?)
  • Are Data Source (given as ADserver in installation program) or Location (given as ADlocation in installation program) used in call to Open or Execute?

I tried to remove either aADOconnection.provider:='ADsDSOObject'; or the ConnectionString, and the call works. When I removed both the code for setting provider, and the ConnectionString, the call failed of course. This code snippet is for checking the AD connection, there is a similar (but longer) code block for querying the groups for a user.

Connecstr_S:='Provider=ADsDSOObject;Encrypt Password=False;Data Source='+
  Tsystem.programsettings.sADserver+';Location='+
  Tsystem.programsettings.sADlocation+';Mode=Read;Bind Flags=0;ADSI Flag=-2147483648';
aADOconnection:=TADOConnection.create(nil);
aADOcmd:=TADOCommand.create(nil);
aADOconnection.loginprompt:=false;
aADOconnection.commandtimeout:=30;
aADOconnection.connectoptions:=coConnectUnspecified;
aADOconnection.CursorLocation:=cluseclient;
aADOconnection.isolationlevel:=ilCursorStability;
aADOconnection.mode:=cmunknown;
aADOconnection.provider:='ADsDSOObject';
aADOcmd.commandtype:=cmdUnknown;
aADOcmd.Paramcheck:=false;
aADOcmd.commandtimeout:=30;
aADOcmd.Prepared:=false;
aADOconnection.ConnectionString:=Connecstr_S;
aADOcmd.Connection:=aADOconnecti开发者_StackOverflow社区on;
aADOconnection.open;
result:=true;
try
  SQL:='select displayname from '+quotedstr('LDAP://'+Tsystem.programsettings.sADbaseDN)+
    ' where  '+Tsystem.programsettings.sADuseridAttribute+'='+quotedstr('aaaaaaa');
  aADOcmd.CommandText:=SQL;
  t:=aADOcmd.Execute;
except
  On E:EOleException do result:=false;  //network connection probably missing
end;
aADOconnection.close;
aADOcmd.free;
aADOconnection.free;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜