ADODB组件导致Win7 / Server 2008上的访问冲突 [英] ADODB component causes access violation on Win7/Server 2008

查看:102
本文介绍了ADODB组件导致Win7 / Server 2008上的访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段用Delphi 2005编写的代码,用于在LDAP中搜索用户的特定属性。在Windows 7或Server 2008上运行但在XP或2003上运行时,出现访问冲突。

I have a piece of code written in Delphi 2005 that searches for a particular attribute on a user in LDAP. I get an access violation when this is run on either Windows 7 or Server 2008, but not on XP or 2003.

Function IsSSOUser(UserId: String): Boolean;
var
  S : string;
  ADOQuery : TADOQuery;
  ADOConnectionSSO: TADOConnection;
begin
  result := false;
  Setdomainname;
  ADOQuery := TADOQuery.Create(nil);
  ADOConnectionSSO := TADOConnection.Create(nil);
  try
    ADOConnectionSSO.LoginPrompt := false;
    ADOConnectionSSO.Mode := cmRead;
    ADOConnectionSSO.Provider := 'ADsDSOObject';
    ADOQuery.Connection := ADOConnectionSSO;
    ADOQuery.ConnectionString := 'Provider=ADsDSOObject;Encrypt Password=False;Mode=Read;Bind Flags=0;ADSI Flag=-2147483648';
    ADOQuery.SQL.Clear;
    try
      S := 'SELECT AdsPath, CN, SN, SSOguid FROM '''
           + LDAPString + ''' WHERE objectClass=''user'' and CN = ''' + UserId + ''' ';
      ADOQuery.SQL.Add(S);
      ADOQuery.Open;
      ADOQuery.ExecSQL;
      if trim(ADOQuery.FieldByName('SSOguid').AsString) = '' then
        result := false
      else
        result := true;
    except
      on e:Exception do
        if e.ClassType <> EOleException then
          Showmessage(format('[%s] Exception in IsSSOUser: [%s]',[e.ClassType.ClassName, e.Message]));
    end;
  finally
    ADOQuery.Close;
    ADOConnectionSSO.Close;
    ADOQuery.free;
    ADOConnectionSSO.free;
  end;
end;

此代码在Windows XP和Windows Server 2003上都可以正常运行,但在两个Windows上都出现访问冲突7和Server2008。我在网上看到了许多有关ADODB接口更改如何破坏下游OS上的东西的线程,但是我似乎遇到了相反的问题。我在Windows 7计算机上构建,该代码仅在Windows的早期版本中有效。

This code works fine on Windows XP and Windows Server 2003, but I get an access violation on both Windows 7 and Server 2008. I see a number of threads online about how changes to ADODB interface can break things on downstream OSes, but I am seemingly having the opposite problem. I'm building on a Windows 7 machine and the code only works on previous versions of Windows.

推荐答案

您将必须添加

AdoQuery.ParamCheck := false;

在您的

ADOQuery.SQL.Add(S);

因为您的LDAPString可能包含冒号()。 LDAP:// .... 导致查询尝试为其创建参数对象。另外,在 ADOQuery.Open 之后不需要 ADOQuery.ExecSQL

since your LDAPString may contains a colon (:) eg. "LDAP://...." which causes the query to try create a parameter object for it. In addition there is no need for ADOQuery.ExecSQL after ADOQuery.Open.

这篇关于ADODB组件导致Win7 / Server 2008上的访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆