Click here to Skip to main content
15,891,763 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I am using .NET Framework 4.0 in that i have created one windows application to get the Active directory details
i have used appconfig file to give the configuration of machine
when i try to fetch the details from Active directory it gives the user list when it was connected to network but when unplug my system from network it's not working it raise the Directory Entry.Guid File not found exception but in network connection it get success
please help me to solve this issue

my appconfig file
XML
<configSections>
      <sectionGroup name="Servers" type="System.Configuration.ConfigurationSectionGroup" >
        <section name="server1" type="System.Configuration.NameValueSectionHandler" />
      </sectionGroup>
    </configSections>
  <Servers>
   
    <server1>
      <add key="connectionstring" value="Data Source=datasource;Initial Catalog=database;User ID=xx;Password=password"/>
      <add key="entrypath" value="WinNT://domain/systemname"/>
      <add key="Username" value="domain\username"/>
      <add key="password" value="password"/>
    </server1>


C#
foreach (ConfigurationSection config_section in section.Sections)
                        {
                            try
                            {
                                var servers = ConfigurationManager.GetSection(config_section.SectionInformation.SectionName) as NameValueCollection;

                                connection_string = servers["connectionstring"].ToString();
                                string Entrypath = servers["entrypath"].ToString();
                                string username = servers["Username"].ToString();
                                string password = servers["password"].ToString();
                                password = oVWSec.DecryptData(password);
                                DirectoryEntry entryPC = new System.DirectoryServices.DirectoryEntry(Entrypath, username, password);
                                
                                try
                                {
                                    debug_string.WriteLine("Connect to Server: " + Entrypath);
                                    WriteLog("Connect to Server: " + Entrypath);
                                    foreach (System.DirectoryServices.DirectoryEntry child in entryPC.Children)
                                    {
                                         //code to manipulate child node
}
}


it raise the error in entryPC.Children
in the following line
foreach (System.DirectoryServices.DirectoryEntry child in entryPC.Children)

help me to solve this
Posted

1 solution

The networking layer in Windows requires a connected network to even load and be active.

Your best option under this condition is to add a "Microsoft Loopback Network adapter" and configure it with an IP address of say 192.168.10.1 for example and everything will work.
 
Share this answer
 
Comments
Sankaralingam Muthusamy 18-Sep-13 2:33am    
Hi Mehdi,
Thank you for your valuable reply
is there any Other option to achieve this using code.
Mehdi Gholam 18-Sep-13 2:57am    
Unfortunately not.
Sankaralingam Muthusamy 18-Sep-13 4:20am    
Ok thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900