简体   繁体   中英

Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. when access local database

I have no idea.. why this occurs. In debug mode it is running well . however, now I am trying to run my project in IIS web server and it doesn't runs well. I can access the main page of my project. but when I try to access the local database, the following error shows up. this is my log file and codes:

            catch (Exception ex)
            {
                Debug.WriteLine("Error in integration: " + ex.Message);
                Debug.Flush();

                StreamWriter file2 = new StreamWriter("c:\\resources\\file.log", true);
                file2.WriteLine("아님여기?"+ex.Message);
                file2.Close(); //디버깅 계속................
            }

In this catch I have the following error:

provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server

I am sorry that I can not explain which line is generating this exception because there's no exception occurring in debug mode...

Here is the code for Page Load:

    protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Form.Enctype = "multipart/form-data";

        WA = Request.QueryString["WA"];
        if (string.IsNullOrEmpty(WA)) WA = "off";
        string qstr = null;
        qstr = Request.QueryString["vCnt"]; //ㅇㅈ이파라메터 들은 어디서...??
        if (qstr != null && qstr != "") vCnt = Int32.Parse(qstr);

        if (!IsPostBack)
        {
            Keywords = Request.QueryString["keywords"];  //ㅇㅈ search main -> searh 버튼 클릭
            VideoSearch = Request.QueryString["VideoSearch"];//ㅇㅈ ~^~^~

            // 스마트폰에서 포스팅 되었을 때
            if (Request.UserAgent.Contains("Android"))
            {
                if (Request.Cookies["VIDEOSEARCH"] != null && Request.Cookies["VIDEOSEARCH"].Value != "")
                {
                    VideoSearch = Request.Cookies["VIDEOSEARCH"].Value;
                    MAM.Models.Utils.CookieManager("VIDEOSEARCH", "");
                }
            }

            if (!String.IsNullOrEmpty(Keywords) && !Keywords.Contains("null")) SearchTextbox2.Text = Keywords;

            Debug.WriteLine("search text is " + SearchTextbox2.Text);
            Debug.Flush();

            try
            {
                if (!string.IsNullOrEmpty(VideoSearch))
                {

                    //ㅇㅈ DNA를 추출하여 유사 동영상을 돌려받음.
                    string results = RetrieveDNAfromVideo(System.Web.HttpUtility.UrlDecode(VideoSearch)/*video name*/);

                    string[] lines = results.Split(new string[] { "\r\n" }, StringSplitOptions.None);
                    vSearchResults = new List<VSearchResult>();
                    foreach (string line in lines)
                    {
                        string[] words = line.Split(',');
                        VSearchResult vSearchResult = new VSearchResult();
                        vSearchResult.VideoID = Int32.Parse(words[0]);
                        vSearchResult.idx = Int32.Parse(words[1]);
                        vSearchResult.RGBdifferce = Int32.Parse(words[2]);
                        vSearchResults.Add(vSearchResult);
                    } //ㅇㅈ vSearchResults : RetrieveDNAfromVideo가 알려준유사동영상정보
                    MAMDataContext db = new MAMDataContext();
                    List<int> VideoIDs = (List<int>)vSearchResults.Select(v => v.VideoID).ToList();
                    //vdo = (List<Video>)(from a in db.Video
                    //                    join b in vSearchResults
                    //                        on a.id equals b.VideoID
                    //                    orderby b.RGBdifferce
                    //                    select a).ToList();
                    vdo = (List<Video>)(from a in db.Videos
                                        where VideoIDs.Contains(a.id)
                                        select a).ToList();  //ㅇㅈ vdo는 결국, RetrieveDNAfromVideo가 알려준유사동영상정보-> id가 같은동영상들
                    vSearchResults2 = new List<VSearchResult2>();
                    VSearchResult v1 = null;
                    foreach (Video v in vdo)
                    {
                        VSearchResult2 v2 = new VSearchResult2();
                        v2.VideoID = v.id;
                        v2.overview = v.overview;
                        v2.title = v.title;
                        v2.filename720 = v.filename720;
                        v2.filename360 = v.filename360;
                        v1 = vSearchResults.Where(t => t.VideoID == v.id).OrderBy(t => t.RGBdifferce).FirstOrDefault();//ㅇㅈ ㅇㄱㅁㅇ
                        // ㅇㅈ RetrieveDNAfromVideo가 알려준유사동영상정보-> id가 같은동영상들[-> RGBdifferce가 가장작은 애]  [] 무슨의미?? 

                        v2.idx = v1.idx;
                        v2.RGBdifferce = v1.RGBdifferce;
                        vSearchResults2.Add(v2);
                    }
                    Debug.WriteLine("Video Serach done");
                    Debug.Flush();
                }
                if (!string.IsNullOrEmpty(Keywords))
                {
                    string ret2 = null;
                    string str1 = null;
                    if (string.IsNullOrEmpty(Keywords))
                    {
                        Keywords = SearchTextbox2.Text;
                    }
                    if (string.IsNullOrEmpty(str1)) str1 = Keywords; //ㅇㅈ str1 은 질의의도??
                    string[] searchTextArray = str1.Split(' ');
                    int cnt1 = searchTextArray.Count();
                    string st1 = ""; string st2 = ""; string st3 = "";
                    if (cnt1 > 0) st1 = searchTextArray[0];
                    if (cnt1 > 1) st2 = searchTextArray[1];
                    if (cnt1 > 2) st3 = searchTextArray[2];

                    MAMDataContext db = new MAMDataContext();
                    vdo = (List<Video>)db.Videos.Where(v => v.overview.Contains(st1)
                                            || (cnt1 > 1 ? v.overview.Contains(st2) : false)
                                            || (cnt1 > 2 ? v.overview.Contains(st3) : false)).ToList();//ㅇㅈ 검색어를 overview에 가지고 있는 동영상 리스트

                    vSearchResults2 = new List<VSearchResult2>();
                    foreach (Video v in vdo)
                    {
                        VSearchResult2 v2 = new VSearchResult2();
                        v2.VideoID = v.id;
                        v2.overview = v.overview;
                        v2.title = v.title;
                        v2.filename720 = v.filename720;
                        v2.filename360 = v.filename360;
                        v2.idx = 0;
                        v2.RGBdifferce = 0;
                        vSearchResults2.Add(v2);
                    }
                    Debug.WriteLine("Video Search");
                }

            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error in integration: " + ex.Message);
                Debug.Flush();

                StreamWriter file2 = new StreamWriter("c:\\resources\\file.log", true);
                file2.WriteLine(ex.Message);
                file2.Close(); //디버깅 계속................
            }

            Debug.WriteLine("Search End");
        }
        if (fUpload.PostedFile != null)    //ㅇㅈ 
        {
            fileupload1();

        }
        else
        {
        }
    }

this is a guess because you did not provide a key information: the connection string.

my guess is that the application is using integrated authentication hence while debugging the access to the database is done using your credentials: as the developer you are likely allowed to do almost everything on the db so the application works correctly.

when the application is deployed the login to the database is performed using the credentials of the application pool used to run the application itself.

as a test you can change the user of the application pool on the iis server to use an account enabled on the db and retry to login.

there are two solutions:
- configure the application pool to use a specific windows user that is allowed to interact with the db
- change the connection string to log onto the db as a sql user (allowed to interact with the db)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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