gpt4 book ai didi

entity-framework - Entity Framework 代码优先 Azure 连接

转载 作者:行者123 更新时间:2023-12-04 07:24:44 24 4
gpt4 key购买 nike

我正在使用 Entity Framework Code First 4.3 + Azure,但连接到数据库时遇到困难。我得到的错误如下(在第一个查询中):

Keyword not supported: 'server'.

我在 Web.config 中设置了以下连接

<configSections>
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>

<connectionStrings>
<add name="TestDBContext"
connectionString="Server=tcp:[SUBSCR].database.windows.net,1433;Database=[MyDB];User ID=[user];Password=[pass];Trusted_Connection=False;Encrypt=True;PersistSecurityInfo=True"
providerName="System.Data.EntityClient" />
</connectionStrings>

我的 DbContext 实现类使用连接字符串的名称:

public class MyContext : DbContext, IMyContext
{
public MyContext()
: base("TestDBContext")
{
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
}

你能告诉我发生了什么吗?

最佳答案

我也遇到了同样的问题。

您缺少 Entity Framework 所需的连接字符串中的所有元数据。 SQL Azure 提供的连接字符串需要插入 provider connection string 内EF连接字符串参数。

<add name="MyConnectionString" connectionString="metadata=res://*/Model.Model.csdl|res://*/Model.Model.ssdl|res://*/Model.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;[PUT SQL AZURE CONN STRING HERE]&quot;" providerName="System.Data.EntityClient" />

您需要使用您自己项目中的元数据。我从现有数据库生成的 EF 项目中提取了该元数据。

关于entity-framework - Entity Framework 代码优先 Azure 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9240618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com