0

I have a UWP app running successfully on my local machine connecting to a test database on the same machine. However, now I have to deploy the app to my work's Windows Server.

I cannot get the app to connect to the SQL Server database, which is running on the same machine as Windows Server. The error message is "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."

All the settings on the database seem to be correct. To test that, I created a simple .NET Core app to see if it could connect. It can. Here is the code:

 using (SqlConnection connection = new SqlConnection("Data Source=ServerName,Portnumber;Initial Catalog=DatabaseName;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False")) ...

However, the UWP app, using the same connection string, cannot connect. Here is the relevant code. This code resides in a .Net Standard 2.0 project that uses EF Core 2.2.6. (I can't use EF Core 3.0 because it's not compatible with .Net Standard 2.0. I have to use .Net Standard 2.0, because 2.1 is not compatible with UWP.)

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseSqlServer("Data Source=ServerName,Portnumber;Initial Catalog=DatabaseName;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"); ...

I can also connect to the server successfully using SSMS.

In the UWP app's capability checkboxes, I have checked Enterprise Authentication and Private Networks.

In summary, I can connect via SSMS and a simple .NET Core app, but I my UWP app cannot connect. Can anyone point me in the right direction? Is this an issue with EFCore perhaps?

Matt
  • 145
  • 1
  • 13
  • When you get errors you should include the error message so others have some kind of idea what the problem might be. – Sean Lange Oct 16 '19 at 16:43
  • Sean -- Thanks for taking a look at the question. I should have added that. Edited to include error message. – Matt Oct 16 '19 at 16:57
  • [Connection Strings](https://learn.microsoft.com/en-us/ef/core/miscellaneous/connection-strings) suggests that you need to change `Data Source` to `Server`, `Initial Catalog` to `Database` and so on... – AlwaysLearning Oct 16 '19 at 21:55
  • According to this error, it means that the SQL Server computer can't be found or that the TCP port number is either not known, or is not the correct port number, or is blocked by a firewall, please check these points first. Abdout more details, you can refer this [document](https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine?view=sql-server-ver15). In addition, if you use sqlconnect to connect the database, will the same issue occur? – Faywang - MSFT Oct 17 '19 at 03:31
  • Thanks Faywang. I'm not sure how to use SQLConnect. However, I can connect through SSMS and a simple .NET Core app. I cannot figure out why the UWP app cannot connect when the other app can. – Matt Oct 17 '19 at 12:59
  • 1
    local network access is forbidden for UWP apps. You need to [enable loopback first](https://docs.telerik.com/fiddler/Configure-Fiddler/Tasks/ConfigureFiddlerForWin8) – magicandre1981 Oct 17 '19 at 15:02
  • That did it. When I enabled loopback on the Windows Server machine, using the Powershell command from the links you provided, it worked. Thanks so much!!! – Matt Oct 17 '19 at 17:22
  • More docs: https://msdn.microsoft.com/en-us/library/windows/apps/hh780593.aspx#enable_loopback_for_network_access – bricelam Oct 17 '19 at 18:27
  • ok, as this was already asked several time, I voted to close it as duplicate. – magicandre1981 Oct 18 '19 at 13:32
  • Accepted marking this as a duplicate. I had seen that question earlier but just failed to realize it was my same issue. – Matt Oct 18 '19 at 17:23

0 Answers0