locked
C# 및 SQL server Express 관련 질문입니다. RRS feed

  • 질문

  • 안녕하세요.

    SQL server와 C#으로 UWP 앱 개발을 연습중인데, 문제가 발생을 해서 질문을 올립니다.

    구글링으로 예제를 찾아서 VS 2019에서 코딩을 해서 빌드를 했는데, DB와 연결이 안 되는군요.

    참고로 예제는 https://github.com/StefanWickDev/IgniteDemos/tree/master/NorthwindDemo 에서 가져온 것입니다.

    문제가 되는 부분의 코드는 다음과 같습니다.

     private async Task LoadProductsAndCategories()
            {
                Products = DataHelper.GetProducts((App.Current as App).ConnectionString);
                if (Products is ProductList)
                {
                    // Store list of all products available at App level
                    (App.Current as App).Products = Products;
                    InventoryList.ItemsSource = Products;
                    Categories = DataHelper.GetCategories((App.Current as App).ConnectionString);
                    Categories.Insert(0, new Category(0, "<Show all categories>"));
                }
                else
                {
                    await new MessageDialog("Unable to connect to SQL Server! Check connection string in Settings.").ShowAsync();
                }
            }

    이 코드에서 ConnectionString 부분은 App.Xaml.cs 파일에 다음과 같이 프로퍼티로 정의하였습니다.

     private string connectionString =
               @"Data Source=localhost\SQLEXPRESS;Initial Catalog=NORTHWIND;Integrated Security=SSPI";
    
     public string ConnectionString { get; set; }

    빌드하고 실행하면 배포까지는 이상없이 되는데 DB와 연결이 안 되는군요.

    여러분들의 조언을 기다립니다.

    감사합니다.

    update> error msg를 보니 "The connectionString property has not been initialized" 라고 나오는데, 여기서 어떻게 손을 대야 하는지 좀 가르쳐 주심 감사하겠습니다.


    • 편집됨 ohseihyung 2019년 8월 17일 토요일 오전 10:57
    2019년 8월 17일 토요일 오전 9:31

답변

  • 해당 연결 문자열은 윈도우즈 통합 인증을 사용한다는 것인데, UWP에서는 이것이 기본적으로 비활성화되어 있습니다. (UWP 앱은 일반 데스크톱 응용 프로그램과 동일한 윈도우 인증 권한을 갖지 않습니다.)

    따라서, 해결 방법은 1) SQL 로그인 인증을 따르도록 변경하거나, 2) Package.appxmanifest에서 Capabilities의 "Enterprise Authentication"을 활성화하는 것입니다.

    관련해서 다음의 글에 내용을 정리했습니다.

    UWP 앱에서 SQL Server 데이터베이스 연결 방법
    ; http://www.sysnet.pe.kr/2/0/12008

    • 답변으로 표시됨 ohseihyung 2019년 8월 28일 수요일 오전 8:49
    • 편집됨 SeongTae JeongMVP 2019년 8월 28일 수요일 오후 2:14
    2019년 8월 25일 일요일 오후 11:56