Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用UWP连接到SQL server时出现问题_C#_Sql Server_Uwp_Connection String - Fatal编程技术网

C# 使用UWP连接到SQL server时出现问题

C# 使用UWP连接到SQL server时出现问题,c#,sql-server,uwp,connection-string,C#,Sql Server,Uwp,Connection String,我创建了一个UWP应用程序,尝试连接到另一台计算机上托管的SQL Server数据库。我正在尝试使用下面的代码连接到此服务器。但是,在尝试打开与服务器的连接时,我得到了我理解为“超时”的错误。我可以在单独的WPF应用程序上使用相同的连接字符串完美地连接到服务器 有关我的应用程序的其他一些详细信息: 最低和最高版本设置为“Windows 10秋季创建者更新” 应用程序是最小的,只有一个按钮和标签。 如有需要,可提供更多详细信息 编辑:我的问题是“有什么想法可以解释为什么使用“Windows10Fa

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

有关我的应用程序的其他一些详细信息:
最低和最高版本设置为“Windows 10秋季创建者更新”
应用程序是最小的,只有一个按钮和标签。
如有需要,可提供更多详细信息

编辑:我的问题是“有什么想法可以解释为什么使用“Windows10FallCreators更新”可以在WPF中很好地工作,但在UWP中却不能工作,它显然完全支持SQLServer连接?”

我的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();
                }
            }
        }
    }
错误消息:

    System.Data.SqlClient.SqlException
  HResult=0x80131904
  Message=A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid)
  Source=Core .Net SqlClient Data Provider
  StackTrace:
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at App2.MainPage.Button_Click(Object sender, RoutedEventArgs e) in C:\Users\DVR-Laptop-02\source\repos\App2\App2\MainPage.xaml.cs:line 50

Inner Exception 1:
SocketException: The operation completed successfully

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

  • 企业认证

  • privateNetworkClientServer


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

  • 企业认证

  • privateNetworkClientServer


启用企业身份验证和privateNetworkClientServer功能后,如果未运行,请使用C验证启用相应功能的应用程序


我将连接字符串改为工作TCP/IP,现在工作正常

启用企业身份验证和privateNetworkClientServer功能后,如果未运行,请使用C验证启用相应功能的应用程序


我将连接字符串改为工作TCP/IP,现在工作正常

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

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

您是否在appx清单中添加了访问此资源所需的网络功能?可能没有。我不完全确定需要向清单中添加什么才能正确连接,如果需要,如何添加。编辑,不,我没有。我刚刚添加了所有内容,效果很好。您知道我特别需要哪些功能来连接而不是添加每个功能吗?我在下面的回答中列出了这些功能。如果您在appx清单中添加所需的网络功能来访问此资源,可能不会。我不完全确定需要向清单中添加什么才能正确连接,如果需要,如何添加。编辑,不,我没有。我刚刚添加了所有内容,效果很好。你知道我特别需要哪些功能来连接,而不是添加每个功能吗?我在下面的回答中列出了这些功能