在 UWP 应用程序上将 Entity Framework Core 与 SQL Server 一起使用时出错 [英] Error using Entity Framework Core with SQL Server on UWP app

查看:14
本文介绍了在 UWP 应用程序上将 Entity Framework Core 与 SQL Server 一起使用时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 Entity FrameWork Core 2.0.2 和 SQL Server、Sqlite 和 PostgreSql 提供程序的数据项目(.net 标准 2.0).

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

我有更多三个项目要在 Windows 窗体、WPF 和 UWP 中进行演示.

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

当我运行 Windows 窗体和 WPF 时,Entity Framework Core 适用于所有提供程序,但是当我尝试在 UWP 上运行 SQL Server 提供程序时,它抛出这个

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

方法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?

推荐答案

我将连接字符串更改为使用 TCP/IP

I changed the connection string to use TCP/IP

之前

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

之后

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

同样需要在sql server中开启TCP/IP连接

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

现在可以使用了!!!

这篇关于在 UWP 应用程序上将 Entity Framework Core 与 SQL Server 一起使用时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆