.net - EF 代码首先存在 SQL Azure 数据库

标签 .net sql entity-framework azure ef-code-first

我使用 Code First 在本地服务器上成功创建了数据库,并将其迁移到 Azure,现在我想使用 Azure 连接字符串和我现有的 POCO 类连接到该数据库。

我的连接字符串:

<add name="CijenolomciContext" connectionString="Data Source=*.database.windows.net;Initial Catalog=NewCijenolomci;Persist Security Info=True;User ID=Bip*;Password=**;MultipleActiveResultSets=False&quot;" providerName="System.Data.EntityClient" />

但是这部分代码恰好在服务器上没有执行任何操作:

Item i = new Item();
            i.Name = "Cranberry";
            i.OldPrice = new decimal(25.99);
            i.NewPrice = new decimal(14.99);
            i.SaleStarts = DateTime.Parse("2012-01-21");
            i.CategoryID = 1;
            context.Items.Add(i);
            context.SaveChanges();

如何成功添加?

编辑: 这种方法恰好修改了我的本地数据库,而不是服务器数据库。

最佳答案

对我来说,您似乎没有连接到 Azure 数据库。我希望连接字符串更像这样。

Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;Encrypt=True;

Use 'username@servername' for the User ID parameter.

参见Connection Strings for SQL Azure .

关于.net - EF 代码首先存在 SQL Azure 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9839313/

相关文章:

c# - dnx451 RC1 InMemorySymmetricSecurityKey 发生了什么?

mysql - 为什么 SELECT ... WHERE last_name = 0 返回所有行?

entity-framework - 为什么 `DatabaseGeneratedOption.None` 存在?

c# - SerialPort.Open() --IOException -- "The parameter is incorrect."

c# - 将 JSON 响应流转换为字符串

MySQL Limit 2 如何选择第二行

c# - 通过 Entity Framework 中的变量引用表

wpf - 将生成的 ADO.Net DbContext 放入 View-Models 的最佳方法

c# - 使用负载均衡器的 ASP.NET 应用程序生命周期

sql - 创建一个触发器,在从条件过滤后从其他表复制少量数据