Active directory Active directory服务器无法运行。错误代码2147016646

Active directory Active directory服务器无法运行。错误代码2147016646,active-directory,Active Directory,C#的新成员。我正在尝试浏览某个特定OU的广告。我得到以下错误。错误代码2147016646。我试着用更高的权限运行这个程序。但仍然得到相同的错误 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.DirectoryServices; using System.DirectoryServices.ActiveDirectory; namespace

C#的新成员。我正在尝试浏览某个特定OU的广告。我得到以下错误。错误代码2147016646。我试着用更高的权限运行这个程序。但仍然得到相同的错误

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.DirectoryServices;
using System.DirectoryServices.ActiveDirectory;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
             string objectPath = "Server1";
             try
             {
                if (DirectoryEntry.Exists("LDAP://" + objectPath))
                    Console.WriteLine(objectPath + "exists");
                else
                    Console.WriteLine(objectPath + " does not exists");
            }
            catch (DirectoryServicesCOMException e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }      
    }
}

对于LDAP路径,您可能需要使用的不仅仅是“Server1”

尝试以下方法:

string objectPath = "Server1/cn=Users,dc=yourcompany,dc=som";
try
{
   if (DirectoryEntry.Exists("LDAP://" + objectPath))
      Console.WriteLine(objectPath + "exists");
   else
      Console.WriteLine(objectPath + " does not exists");
}
这将检查服务器上是否存在默认的“用户”容器

马克