Set objCon = Server.CreateObject("ADODB.Connection")
Set objCommand = Server.CreateObject("ADODB.Command")'--- Setting Connection parameter ---
objCon.Provider = "ADsDSOObject"
objCon.Properties("User ID") = ADMIN_USER
objCon.Properties("Password") = ADMIN_PASSWD
objCon.Properties("Encrypt Password") = True
objCon.Provider = "ADsDSOObject"
objCon.OpenstrSQL = "SELECT AdsPath FROM 'LDAP://gend.pst.local/OU=gend root,DC=gend,DC=pst,DC=local' WHERE objectClass = 'user' AND samAccountName='" & searchaccount & "'"
objCommand.CommandText = strSQL
objCommand.Properties("searchscope") = 2
objCommand.Properties("Cache Results") = False
objCommand.CommandType = 1Set objRecordSet = objCommand.Execute

解决方案 »

  1.   

    _ConnectionPtr pConn("ADODB.Connection" );
    _CommandPtr  pCommand("ADODB.Command");
      

  2.   

    大体过程(不一定准确): IADORecordBinding   *picRs = NULL;
    _RecordsetPtr pRs("ADODB.Recordset");
    _ConnectionPtr pConn("ADODB.Connection" );
    _CommandPtr  pCommand("ADODB.Command"); CString strPri,strSQL; strSQL = "SELECT AdsPath FROM 'LDAP://gend.pst.local/OU=gend root,DC=gend,DC=pst,DC=local' WHERE objectClass = 'user' AND samAccountName=' " &searchaccount& " ' "; strPri = strPri +
     "Provider=Microsoft.Jet.OLEDB.4.0;" +
     "Data Source = ADsDSOObject " +
     ";Persist Security Info=False;Jet OLEDB:Database Password = ADMIN_PASSWD User ID = ADMIN_USER;"; pCommand->CommandText = (_bstr_t)strSQL; try
    {
    pConn->Open((_bstr_t)strSql, "", "", adModeUnknown);
    pCommand.CreateInstance(__uuidof(Command));
    pCommand->Execute(NULL, NULL, adCmdText);
    }
    catch(...)
    {}
      

  3.   

    you need import ADO COM,just like
    #import "c:\...\msado15.dll" using_namespace("ADODC")
      

  4.   

    before you using the COM,you have to call CoInitialize() and call CoUninitialize() at last for initialize the COM
      

  5.   

    我在程序开始加了#import "msado15.dll" using_namespace("ADODC")
    并且把msado15.dll拷贝到system32下了但是引用
    IADORecordBinding   *picRs = NULL;
    _RecordsetPtr pRs("ADODB.Recordset");
    _ConnectionPtr pConn("ADODB.Connection" );
    _CommandPtr  pCommand("ADODB.Command");
    的时候 还是说我没有定义
      

  6.   

    #include <icrsint.h>
    #include <basetsd.h>
    #include <ole2.h>#import "c:\Program Files\Common Files\System\ADO\msado15.dll"     no_namespace rename("EOF", "EndOfFile")
      

  7.   

    taianmonkey() 好厉害!
    先说一句:请容忍菜鸟!请问一下strSQL这个变量应该放在哪里?我要实现的功能是从域的系统数据库中取得用户的mail和真名。对于vc我是个菜鸟,这个功能用asp已经实现了,转到vc中,请大家言无不尽呀!
    asp代码如下<%
    Const ADMIN_USER = "ps\Administrator"
    Const ADMIN_PASSWD = "dfgdfg"
    %><%
    Dim time1,time2  time1 = timer   Call Test("jo")
      Call Test("pf72319")
      Call Test("asagi")
      Call Test("advice")
      Call Test("mmva58z")
      Call Test("mcp2e1")
      Call Test("mr5t4diz")
      Call Test("mh8jnm")
      Call Test("xuli13")
      Call Test("md3zk")  time2 = timer   response.write time2-time1%><%
    Sub Test (searchaccount)Dim objCon     '--- ConnectionObject
    Dim objCommand '--- CommandObject
    Dim objRecordSet '- RecordsetObject
    Dim objError   '--- ErrorObject
    Dim objData    '--- For Get DataDim strSQL     '--- SQL string
    Dim strError   '--- Error string'--- Set up the connection ---
    Set objCon = Server.CreateObject("ADODB.Connection")
    Set objCommand = Server.CreateObject("ADODB.Command")'--- Setting Connection parameter ---
    objCon.Provider = "ADsDSOObject"
    objCon.Properties("User ID") = ADMIN_USER
    objCon.Properties("Password") = ADMIN_PASSWD
    objCon.Properties("Encrypt Password") = True
    objCon.Provider = "ADsDSOObject"
    objCon.Open    '--- connenct ---Set objCommand.ActiveConnection = objCon'--- Execute the query for the user in the directory ---
    strSQL = "SELECT AdsPath FROM 'LDAP://gend.pst.local/OU=gend root,DC=gend,DC=pst,DC=local' WHERE objectClass = 'user' AND samAccountName='" & searchaccount & "'"
    objCommand.CommandText = strSQL
    objCommand.Properties("searchscope") = 2
    objCommand.Properties("Cache Results") = False
    objCommand.CommandType = 1On Error Resume Next ' --- Execute SQL
    Set objRecordSet = objCommand.Execute
    '//
    If objCon.Errors.Count > 0 Then
    For Each objError In objCon.Errors
    strError = strError & "Error #" & Hex(objError.Number) & "<BR>" & _
    " " & objError.Description & "<BR>" & _
    "NativeError:" & Hex(objError.NativeError) & "<BR>" & _
    "SQLState:" & objError.SQLState & "<BR>" & _
    "Reported by:" & objError.Source & "<BR>" & _
    "Help file:" & objError.HelpFile & "<BR>" & _
    "Help Context ID:" & objError.HelpContext
    Next
    response.Write strError
    End If' ---Display Search Result ---' Debug
    'response.Write "結果= " & objRecordSet.RecordCount & "(" & objRecordSet.Fields.Count &  ")<BR>"For i = 0 To oRecordSet.RecordCount - 1
    ' Debug
    '  response.Write objRecordSet.Fields.item("AdsPath") & "<BR>"' --- Getting Data ---
      Set objData  = GetObject(objRecordSet.Fields.item("AdsPath"))
      username = objData.Get("cn")
      usermail = objData.Get("mail")  ' --- Display Data ---
      response.Write "氏名:" & username & "<BR>"
      response.Write "Mail:" & usermail & "<BR>"  Set objData  = Nothing  objRecordSet.MoveNext
    Next' -- Clean up --
    objRecordSet.Close
    objCon.Close
    Set oRecordSet = Nothing
    Set objCommand = Nothing
    Set objCon = NothingEnd Sub
    %>