Ste*_*asz 6 entity-framework connection-string azure code-first ef-code-first
我正在使用Entity Framework Code First 4.3 + Azure并且无法连接到数据库.我得到的错误如下(在第一个查询上):
Keyword not supported: 'server'.
Run Code Online (Sandbox Code Playgroud)
我在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>
Run Code Online (Sandbox Code Playgroud)
我的DbContext实现类使用连接字符串的名称:
public class MyContext : DbContext, IMyContext
{
public MyContext()
: base("TestDBContext")
{
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = true;
}
Run Code Online (Sandbox Code Playgroud)
你能说出发生了什么吗?
我刚遇到同样的问题.
您缺少Entity Framework所需的连接字符串中的所有元数据.SQL Azure提供的连接字符串需要插入provider connection stringEF的连接字符串的参数中.
<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" />
您需要使用自己项目中的元数据.我从现有数据库生成的EF项目中提取了元数据.
我尝试过这样,它可能对你有帮助。可能是1433有问题,是端口号吗?或者是什么?。尝试这样。
<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" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6881 次 |
| 最近记录: |