Connecting UWP App to Remote SQL Server 2008 provi

2019-02-20 16:38发布

问题:

System.Data.SqlClient.SqlException: 'A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - The operation completed successfully)'

I'm trying to connect to SQL Server 2008 R2 database with a UWP APP.

  • Remote Access is enabled
  • Firewall rules are in place
  • Target version is Windows 10 Fall Creators Update(10.0; Bulid 16299
  • Min version is Windows 10 Fall Creators Update(10.0; Bulid 16299
  • Package.appxmanifest is setup with
    • internetClient
    • internetClientServer
    • privateNetworkClientServer
    • enterpriseAuthentication

Code:

using System.Data.SqlClient;

const string ConnectionString = "SERVER = XXXServer; DATABASE =     XXXDatabase; USER ID = XXXUser; PASSWORD = XXXPass";

using (SqlConnection sqlConn = new SqlConnection(ConnectionString))
        {
            sqlConn.Open();

        }

回答1:

I tested the connection between UWP app and SQL server 2008 R2, and can reproduce your issue. I also tested the connection between UWP app and SQL server 2017, with the same code snippet, same configuration for SQL server, it worked very well. So that as a workaround I strongly recommend you to upgrade the SQL server to 2017 since SQL server 2008 R2 is already out of date that not supported.

Additionally, don't forgget to Enable TCP/IP Network Protocol for SQL Server which you didn't mention it in above description.