簡體   English   中英

錯誤SQL數據讀取器

[英]Error SQL data reader

我創建了與AD連接的Intranet項目,以將用戶的數據檢索為Image,Department。 我做了我的代碼,它運作良好,但我有很多次以下錯誤。

在此輸入圖像描述

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);

當我在過去完成這個問題時,其中一個問題是用戶對象屬性中的異常字符導致了這種錯誤。

一種方法是對您正在設置的每個變量進行錯誤檢查,以便代碼可以繼續工作,或者將所有數據導出到文本文件,並使用excel進行檢查並查找異常或奇怪的控制字符。

如果錯誤總是發生在某個人身上,您可以查看該用戶的屬性,並希望以這種方式找到問題。

我們的問題是在某些領域使用中文簡體字。

希望這可以幫助您追蹤您的問題。

多吉

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM