简体   繁体   English

错误SQL数据读取器

[英]Error SQL data reader

I created Intranet project which connect with AD to retrieve User's data as Image , Department . 我创建了与AD连接的Intranet项目,以将用户的数据检索为Image,Department。 I did my code and it works well but I had the below error a lot of times . 我做了我的代码,它运作良好,但我有很多次以下错误。

在此输入图像描述

string User = ConfigurationManager.AppSettings["User"];
            string Password = ConfigurationManager.AppSettings["Password"];
            var entry = new DirectoryEntry("LDAP://" + "xxxxx", User, Password);

            DirectorySearcher searcher = new DirectorySearcher(entry);
            searcher.SearchScope = SearchScope.Subtree;
            string UserName = Page.User.Identity.Name;
            searcher.Filter = string.Format(CultureInfo.InvariantCulture, "(sAMAccountName={0})", UserName.Split('\\')[1]);
            SearchResult findUser = searcher.FindOne();
            if (findUser != null)
            {
                DirectoryEntry user = findUser.GetDirectoryEntry();
                //string loginuser = user.Properties["UserName"].Value.ToString();
                LoggedUser = user.Properties["displayName"].Value.ToString();
                Session.Add("LoggedUser", LoggedUser);
                LoggedEmail = user.Properties["mail"].Value.ToString();
                Session.Add("LoggedEmail", LoggedEmail);
                string Mobile = user.Properties["Mobile"] != null && user.Properties["Mobile"].Value != null ? user.Properties["Mobile"].Value.ToString() : null;
                string Login = user.Properties["sAMAccountName"].Value.ToString();
                if (user.Properties["Department"].Value != null)
                    LoggedDepartement = user.Properties["Department"].Value.ToString();
                _userDept = user.Properties["Department"].Value != null ? user.Properties["Department"].Value.ToString() : "";
                 ftier.AddLoggedUser(LoggedUser, LoggedDepartement, title, LoggedEmail, data, DateTime.Now, DateTime.Now, " nnnnn", true);

When I've done this in the past one of the problems was unusual characters in the properties of the user object caused this sort of error. 当我在过去完成这个问题时,其中一个问题是用户对象属性中的异常字符导致了这种错误。

One approach would be to put error checking on each of the variables you're setting so the code can keep working, or export to a text file all the data and go through it using excel and look for unusual or strange control characters. 一种方法是对您正在设置的每个变量进行错误检查,以便代码可以继续工作,或者将所有数据导出到文本文件,并使用excel进行检查并查找异常或奇怪的控制字符。

If the error always occurs at a certain person you could just look at the properties of that user and hope to find the issue that way. 如果错误总是发生在某个人身上,您可以查看该用户的属性,并希望以这种方式找到问题。

Our issue was the use of Chinese simplified characters in some fields. 我们的问题是在某些领域使用中文简体字。

Hope this helps you track down your issue. 希望这可以帮助您追踪您的问题。

Dorje 多吉

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM