Runtime: Can't connect to database running on SQL Server on host from UWP

Created on 3 Aug 2017  路  6Comments  路  Source: dotnet/runtime

Try to connect to my SQL Server from UWP. Server is running on localhost.
My console app with the same code can connect to the local database server just fine.

I did the localloopback exempt and it still isn't working.

Tried these versions:
Microsoft.NETCore.UniversalWindowsPlatform 6.0.0-preview1-25602-01

and

Microsoft.NETCore.UniversalWindowsPlatform 6.0.0-preview2-25601-02
System.Data.SqlClient 4.5.0-preview2-25602-01

This is the connection string I use:
conn.ConnectionString = "Server=mahoekst-z400;Initial Catalog=Northwind;Trusted_Connection=True;";

(I also tried a sql login password)

The error I get is:
System.Data.SqlClient.SqlException: '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: 40 - Could not open a connection to SQL Server)'

Code running against Azure SQL is running fine.

Most helpful comment

Besides enabling the TCP protocol you have to set the 'Enterprise Authentication' capability in the Package.appxmanifest. Otherwise 'Trusted_Connection=True' doesn't work.

All 6 comments

@mahoekst Is TCP enabled for this sql instance? .NET Core SqlClient on UWP doesn't fallback to named pipes when TCP fails, since named pipes isn't supported on all platforms.

Thanks, that was it. I brushed up my powershell skills and changed the settings to TCP/IP (i thought that was enabled by default). It has been a while I did my SQL dba stuff.

I can confirm it works on all versions mentioned above and integrated security works as well.

@mahoekst Windows also has a SQL Server Configuration Manager that lets you configure the server networking protocols via a GUI. https://docs.microsoft.com/en-us/sql/relational-databases/sql-server-configuration-manager

Besides enabling the TCP protocol you have to set the 'Enterprise Authentication' capability in the Package.appxmanifest. Otherwise 'Trusted_Connection=True' doesn't work.

Enterprise Authentication capability was not set, works fine when this is set. Thanks.

Enabling enterprise auth also resolved dotnet/corefx#24366.

Was this page helpful?
0 / 5 - 0 ratings