为了账号安全,请及时绑定邮箱和手机立即绑定

使用UWP无法连接到SQL Server

使用UWP无法连接到SQL Server

C#
精慕HU 2021-04-01 10:11:59
我创建了一个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();                }            }        }    }
查看完整描述

3 回答

?
慕尼黑8549860

TA贡献1818条经验 获得超11个赞

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

  • 企业认证

  • privateNetworkClientServer


查看完整回答
反对 回复 2021-04-10
?
江户川乱折腾

TA贡献1851条经验 获得超5个赞

启用功能企业身份验证和privateNetworkClientServer后,如果无法使用,请使用C heckNetIsolation.exe验证启用了适当功能的应用程序。

我的解决方法是将连接字符串更改为可以使用TCP / IP,现在可以正常使用了!


查看完整回答
反对 回复 2021-04-10
?
DIEA

TA贡献1820条经验 获得超2个赞

不要忘记在“计算机管理”下,您可能需要启用TCP / IP服务并重新启动SQL Server,以使这些服务开始为外部连接远程连接到数据库提供帮助。


查看完整回答
反对 回复 2021-04-10
  • 3 回答
  • 0 关注
  • 157 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信