实体框架代码优先 Azure 连接

发布于 2025-01-04 14:37:41 字数 1070 浏览 3 评论 0 原文

我正在使用 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;
        }

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

I am using Entity Framework Code First 4.3 + Azure and having difficulties connecting to the database. The error I get is the following (on the first query):

Keyword not supported: 'server'.

I have the following connection set up in my 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>

My DbContext implementing class uses the connection string's name:

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

Can you tell what is going on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

镜花水月 2025-01-11 14:37:41

我刚刚遇到了同样的问题。

您缺少实体框架所需的连接字符串中的所有元数据。 SQL Azure 提供的连接字符串需要插入到 EF 连接字符串的 provider connection string 参数中。

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

I just had the same problem.

You're missing all the metadata in the connection string that Entity Framework requires. The connection string provided by SQL Azure needs to inserted within the provider connection string parameter of EF's connection string.

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

You'll need to use the metadata from your own project. I pulled that metadata from an EF project generating from an existing database.

不再让梦枯萎 2025-01-11 14:37:41

我也有同样的问题。我解决了,将这个连接字符串放入 web.config 中:

<add name="eManagerTurModelConnection" connectionString="metadata=res://*/ORM.eManagerFinanceModel.csdl|res://*/ORM.eManagerFinanceModel.ssdl|res://*/ORM.eManagerFinanceModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=<server>.database.windows.net;Initial Catalog=eManagerTur;Integrated Security=False;User ID=<user>;Password=<Password>;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

在删除网站的连接字符串后,工作正常,因为它没有获取我在 web.config 中添加的连接字符串。

英语不好... =)

I had the same problem. I solved, putting in the web.config this connectionstring:

<add name="eManagerTurModelConnection" connectionString="metadata=res://*/ORM.eManagerFinanceModel.csdl|res://*/ORM.eManagerFinanceModel.ssdl|res://*/ORM.eManagerFinanceModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=<server>.database.windows.net;Initial Catalog=eManagerTur;Integrated Security=False;User ID=<user>;Password=<Password>;Connect Timeout=15;Encrypt=False;TrustServerCertificate=False;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />

And after I removed the connectionstring of my website, worked, because it was not getting the connection string that I added in my web.config.

English bad... =)

只想待在家 2025-01-11 14:37:41

提供程序应该是providerName =“System.Data.SqlClient”

我从VS连接到Azure,然后查看属性并设置我的连接字符串和提供程序名称。

 <add name="context" connectionString="Data Source=myServer,myPort;Initial Catalog=myDBName;Persist Security Info=True;User ID=myUserName;Password=myPassword;" providerName="System.Data.SqlClient"/>

然后我就可以毫无问题地运行更新数据库。

The provider should be providerName="System.Data.SqlClient"

I connected to Azure from VS and then looked at the properties and set my connection string and provider name.

 <add name="context" connectionString="Data Source=myServer,myPort;Initial Catalog=myDBName;Persist Security Info=True;User ID=myUserName;Password=myPassword;" providerName="System.Data.SqlClient"/>

I was then able to run update-database with no issues.

桃扇骨 2025-01-11 14:37:41

我尝试过这样,它可能对你有帮助。可能是1433有问题,是端口号吗?或者什么? 。尝试这样。

检查此链接 Windows Azure with Sql< /a>

<add name="dbContext" connectionString="Server=tcp:xxxxxxxx.database.windows.net;Database=xxxxxxxx;User ID=xxxxxxx@xxxxxxxxx;Password=xxxxxxxxxx;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.EntityClient" />

i tried like this, it may help you. may be 1433 is making problem, is it port no ? or what? . try like this.

check this link Windows Azure with Sql

<add name="dbContext" connectionString="Server=tcp:xxxxxxxx.database.windows.net;Database=xxxxxxxx;User ID=xxxxxxx@xxxxxxxxx;Password=xxxxxxxxxx;Trusted_Connection=False;Encrypt=True;" providerName="System.Data.EntityClient" />
堇年纸鸢 2025-01-11 14:37:41

试试这个:

数据源=tcp:YOUR-DATABASE-HERE.database.windows.net,1433;
数据库=GolfRounds;
用户ID=您的用户名@您的服务器;密码=您的密码; Trusted_Connection=False;加密=真;

还有一篇 MSDN 文章 http://msdn.microsoft.com/ en-us/library/windowsazure/ff951633.aspx 这可能会有所帮助。

Try this:

Data Source=tcp:YOUR-DATABASE-HERE.database.windows.net,1433;
Database=GolfRounds;
User ID=YOUR-USERNAME@YOUR-SERVER; Password=YOUR-PASSWORD; Trusted_Connection=False; Encrypt=True;

There is also an MSDN article at http://msdn.microsoft.com/en-us/library/windowsazure/ff951633.aspx that may be helpful.

陌路黄昏 2025-01-11 14:37:41

我遇到了类似的问题,我无法访问元数据,在这种情况下,您需要使用 System.Data.SqlClient 作为提供程序。您还需要将 MultipleActiveResultSets=True 添加到连接字符串中

I had a similar problem where I did not have access to the metadata, in this case you need to use System.Data.SqlClient as the provider. You will also need to add MultipleActiveResultSets=True to your connection string

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文