在UWP应用上将Entity Framework Core与SQL Server一起使用时出错 [英] Error using Entity Framework Core with SQL Server on UWP app
问题描述
我有一个使用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
方法<$ c中发生错误$ c> 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
也必须启用TCP / sql服务器中的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屋!