【发布时间】:2016-10-20 07:36:11
【问题描述】:
我在本地机器上使用 Visual Studio 开发了一个新的 .Net 应用程序。我创建了一个 Google Cloud SQL 实例来保存数据库。我正在尝试在服务器上建立代码优先的实体框架数据库,但连接时遇到问题。
我正在关注 Google 提供的指南(虽然很糟糕),但在 Web.config 文件中设置连接字符串时遇到了问题。 导游: https://cloud.google.com/dotnet/getting-started/using-cloud-sql
我已经将我的 IP 添加到云 SQL 端接受的连接中。 我对默认 Web.config 文件所做的唯一更改是:
1) 注释掉现有的连接字符串。 2) 替换为:
<add name="CCGamesGCloud.EntityFramework.Context" connectionString="Data Source=tcp:###.###.##.###;Initial Catalog=CCG-GamesDB;User ID=####;Password=########"
providerName="System.Data.SqlClient" />
以上是使用正确的IP和登录信息代替****,名称是DB上下文的位置
我是否缺少特定的 appSettings 配置键/值?
尝试在服务器资源管理器中查看连接会出现以下错误。 http://imgur.com/a/6DyYv
有人能指出我正确的方向吗?在过去的一个小时里,我一直在谷歌搜索帮助博客,但谷歌似乎喜欢提供自己的愚蠢指南,作为我每次搜索的最佳结果。
上下文类:
public class Context : DbContext
{
public Context() : base("CCGamesGCloud.EntityFramework.Context")
{
}
public virtual DbSet<Developer> Developers { get; set; }
//... etc. etc... for all DBSets
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Developer>();
// other calls... etc here
}
}
【问题讨论】:
标签: .net entity-framework ef-code-first google-cloud-sql