1

I have a data project (.net standard 2.0) with Entity FrameWork Core 2.0.2 and SQL Server, Sqlite and PostgreSql providers.

I have more three projects for presentation in Windows Forms, WPF and UWP.

When I run the Windows Forms and WPF, Entity Framework Core works fine for all providers, but when I try to run the SQL Server provider on UWP, it throw this

enter image description here

The error occurred in the method EnsureCreatedAsync:

public async Task InitDataBaseAsync(DataBaseConfig config)
{
   using (var db = GetDataContext(config))
   {
      // Postgresql and Sqlite do not throw exception in UWP.
      await db.Database.EnsureCreatedAsync();
   }
}

I checked the three platforms connection string, the connection are the same.

Has anyone experienced this problem?

Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
Marks
  • 41
  • 5
  • Is the server running on the same machine as the app? UWP has some restrictions regarding this... – thezapper Apr 17 '18 at 12:23
  • Yes, running on my localhost – Marks Apr 17 '18 at 12:44
  • Have you checked the Enterprise [Authentication](https://learn.microsoft.com/en-us/windows/uwp/data-access/sql-server-databases) option In the Capabilities tab? – Nico Zhu Apr 18 '18 at 08:32
  • I had not checked, but after checking the error persist When I use data project on windows forms work normally – Marks Apr 19 '18 at 01:58
  • The inner exception show : The operation completed successfully and stacktrace >> at System.Data.SqlClient.SNI.SSRP.GetPortByInstanceName(String browserHostName, String instanceName) at System.Data.SqlClient.SNI.SNIProxy.CreateTcpHandle(DataSource details, Int64 timerExpire, Object callbackObject, Boolean parallel) – Marks Apr 19 '18 at 02:00
  • My workaround is to enable TCP / IP by the SQL server configuration Manager and my connection string now uses Data Source = 127.0.0.1,1433; ... now it works! – Marks May 06 '18 at 05:07

2 Answers2

2

I changed the connection string to use TCP/IP

Before

Data Source=xpt/SqlServerExpress;Initial Catalog=gestao_eficaz;User ID=sa;Password=somePassword

After

Data Source=127.0.0.1,1433;Initial Catalog=gestao_eficaz;User ID=sa;Password=somePassword

It is also necessary to enable the TCP / IP connection in the sql server

https://stackoverflow.com/questions/2388042/connect-to-sql-server-2008-with-tcp-ip

Now works !!!

Marks
  • 41
  • 5
1

Enabling and starting the SQL Browser service fixed the problem for me. That avoids messing around with IP addresses and TCP ports.

Integrated security would not work, however, I had to revert to SQL User ID and password.

PatriceBG
  • 11
  • 2