0

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

I'm getting the above error when trying to run the code example on this page: Validate a username and password against Active Directory?. I've also posted my code and would appreciate any help that can be given. Thanks!

        try
        {
            string username = LoginUser.UserName;
            string password = LoginUser.Password;
            using (PrincipalContext pc = new PrincipalContext(ContextType.Domain, "NAUHBAR"))
            {
                bool isValid = pc.ValidateCredentials("NAUHBAR\\" + username, password);
                if (isValid)
                {
                    Response.Redirect("Dashboard.aspx", false);
                }
                else if (!isValid)
                {
                    Response.Write("<script type=\"text/javascript\">alert('Incorrect username or password!');</script>");
                }
            }

        }
        catch (Exception ex)
        {
            throw;
        }
Community
  • 1
  • 1

1 Answers1

0

I actually just figured this out after trying to all day. I used the template that visual studio uses for a login page and it puts it under an account folder. There is a web.config file in there and it was conflicting with what I was trying to do with my edmx connection string.