使用UWP无法连接到SQL Server

我创建了一个UWP应用程序来尝试连接到另一台计算机上托管的SQL Server数据库。我正在尝试使用下面的代码连接到该服务器。但是,在尝试打开与服务器的连接时,我得到的理解是“超时”错误。我可以在单独的WPF应用程序上使用相同的连接字符串完美地连接到服务器。


有关我的应用程序的其他一些详细信息:

最小和最大版本设置为“ Windows 10 Fall Creators Update”

应用程序最小,只有一个按钮和标签。

如果需要,可以提供更多详细信息。


编辑:我的问题是“为什么使用“ Windows 10 Fall Creators Update”显然可以完全支持SQL Server连接,为什么在WPF中可以正常工作而在UWP中不能正常工作?


我的UWP应用:


using System;

    using System.Collections.Generic;

    using System.IO;

    using System.Linq;

    using System.Runtime.InteropServices.WindowsRuntime;

    using Windows.Foundation;

    using Windows.Foundation.Collections;

    using Windows.UI.Xaml;

    using Windows.UI.Xaml.Controls;

    using Windows.UI.Xaml.Controls.Primitives;

    using Windows.UI.Xaml.Data;

    using Windows.UI.Xaml.Input;

    using Windows.UI.Xaml.Media;

    using Windows.UI.Xaml.Navigation;


    using System.Data.SqlClient;


    namespace App2

    {

        public sealed partial class MainPage : Page

        {

            public MainPage()

            {

                this.InitializeComponent();

            }


            private void Button_Click(object sender, RoutedEventArgs e)

            {

                {

                    string connetionString = null;

                    SqlConnection cnn;


                    connetionString = @"Data Source=DIMENSIONVRSERV\DIMENSIONVRDB;Database=mydatabase;Persist Security Info=True;User ID=DVRLaptop;Password=password";


                    cnn = new SqlConnection(connetionString);


                    cnn.Open();

                    Lbl_ConState.Text = "Connection Open ! ";

                    cnn.Close();

                }

            }

        }

    }


精慕HU
浏览 170回答 3
3回答

慕尼黑8549860

您将需要声明以下一项或两项功能(取决于您的网络设置):企业认证privateNetworkClientServer

江户川乱折腾

启用功能企业身份验证和privateNetworkClientServer后,如果无法使用,请使用C heckNetIsolation.exe验证启用了适当功能的应用程序。我的解决方法是将连接字符串更改为可以使用TCP / IP,现在可以正常使用了!

DIEA

不要忘记在“计算机管理”下,您可能需要启用TCP / IP服务并重新启动SQL Server,以使这些服务开始为外部连接远程连接到数据库提供帮助。
打开App,查看更多内容
随时随地看视频慕课网APP