我在本地机器上使用Visual Studio开发了一个新的.Net应用程序。我创建了一个Google Cloud SQL实例来存放数据库。我试图在服务器上建立一个代码优先的实体框架数据库,并且遇到连接问题。无法连接到GCloud SQL
我按照谷歌提供的指南(糟透了,因为它),并且在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
有人可以指出我在正确的方向吗?我一直在谷歌搜索帮助博客过去一小时,但谷歌似乎喜欢给自己愚蠢的指导作为我做的每一个搜索的最高结果。
Context类:
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
}
}
见下面链接,产生额外的帮助,任何基于MySQL的链接: http://stackoverflow.com/questions/20277677/dynamic-mysql-database-connection-for-entity-framework-6/20294903#20294903 – Chris