背景:

之前项目使用的是DB first/Model first,现在要对EF升级的6.0,并且更换成Code first。

问题:

1. System.Data.Entity.Core.MetadataException: Unable to load the specified metadata resource.

<add name="TestContext" connectionString="metadata=res://*/Test.csdl|res://*/Test.ssdl| res://*/Test.msl;     provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:[***test***].database.windows.net,1433;Initial Catalog=test;persist security info=True;User ID=[***test***];Password=[***test***];multipleactiveresultsets=True;Encrypt=True;Trusted_Connection=false;App=EntityFramework;Connection Timeout=30;&quot;" providerName="System.Data.EntityClient"/>

2. 更改metadata值;

System.ArgumentException: Argument 'xmlReader' is not valid. A minimum of one .ssdl artifact must be supplied.

<add name="TestContext" connectionString="metadata=res://*/;     provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:[***test***].database.windows.net,1433;Initial Catalog=test;persist security info=True;User ID=[***test***];Password=[***test***];multipleactiveresultsets=True;Encrypt=True;Trusted_Connection=false;App=EntityFramework;Connection Timeout=30;&quot;" providerName="System.Data.EntityClient"/>

3. 删除metadata;

System.ArgumentException: Some required information is missing from the connection string. The 'metadata' keyword is always required.

<add name="TestContext" connectionString="    provider=System.Data.SqlClient;provider connection string=&quot;Data Source=tcp:[***test***].database.windows.net,1433;Initial Catalog=test;persist security info=True;User ID=[***test***];Password=[***test***];multipleactiveresultsets=True;Encrypt=True;Trusted_Connection=false;App=EntityFramework;Connection Timeout=30;&quot;" providerName="System.Data.EntityClient"/>

解决方法:

对于code first, connectionstring 跟之前的web form程序里的写法一样;

    <add name="TestContext" connectionString="Data Source=[***DB Server Name];Initial Catalog=[***DB Name***];Integrated Security=True;MultipleActiveResultSets=True"  providerName="System.Data.SqlClient" />

Reference link:

http://blogs.msdn.com/b/adonet/archive/2011/01/27/using-dbcontext-in-ef-feature-ctp5-part-2-connections-and-models.aspx?Redirected=true

MVC: Connection String的更多相关文章

  1. ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB

    您创建的MovieDBContext类负责处理连接到数据库,并将Movie对象映射到数据库记录的任务中.你可能会问一个问题,如何指定它将连接到数据库? 实际上,确实没有指定要使用的数据库,Entity ...

  2. [转]ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB

    您创建的MovieDBContext类负责处理连接到数据库,并将Movie对象映射到数据库记录的任务中.你可能会问一个问题,如何指定它将连接到数据库? 实际上,确实没有指定要使用的数据库,Entity ...

  3. MVC模式下unity配置,报错“No connection string named '**Context' could be found in the application config file”

     写在前面: 第一次配置时好好的,后来第二次改到MVC模式,把依赖注入写成字典的单例模式时,由于新建的ORM(数据库映射模型EF),怎么弄都不用,一直报错"No connection str ...

  4. No connection string named '***' could be found in the application config file

    Code-First时更新数据库遇到妖孽问题“No connection string named '***' could be found in the application config fil ...

  5. Cannot load connection class because of underlying exception: com.mysql.cj.exceptions.WrongArgumentException: Malformed database URL, failed to parse the connection string near ';characterEncoding=UTF

    今天在使用springboot整合SSM的时候,配置好以后启动项目,报了一个这样的异常 java.sql.SQLNonTransientConnectionException: Cannot load ...

  6. How to set China Azure Storage Connection String

    Configure Visual Studio to access China Azure Storage Open Visual Studio 2012, Server Explorer Add n ...

  7. 转载 How to Encrypt connection string in web.config

    转载原地址: https://chiragrdarji.wordpress.com/2008/08/11/how-to-encrypt-connection-string-in-webconfig/ ...

  8. 不支持的关键字:“provider connection string”报错信息及解决方案

    今天在部署公司开发框架的时候 ,登录系统之后调用代办列表的时候就报错了 总线调用契约XX.Service.Contracts.IXXService上的GetXXCount方法时出错. Resoluti ...

  9. [转]Setting the NLog database connection string in the ASP.NET Core appsettings.json

    本文转自:https://damienbod.com/2016/09/22/setting-the-nlog-database-connection-string-in-the-asp-net-cor ...

随机推荐

  1. Scrum 4.0(未完待续)

    看板设计: 每日例会时间定于下午放学回到宿舍,地点是在宿舍外的走廊或宿舍里,特殊情况待定: 团队开会照片: 任务认领: 首页设计-------王俊杰 鸡汤版面-------列志华 论“汤”版面---- ...

  2. TCP&UDP基础

    TCP TCP/IP是一种网络通讯协议,而socket则是TCP/IP网络最为通用的API,即一种应用程序接口,称为套接字.TCP是面向连接的协议,在进行数据收发前必须连接,且在收发时必须保持该连接. ...

  3. Dubbo学习(二) Dubbo 集群容错模式-负载均衡模式

    Dubbo是Alibaba开源的分布式服务框架,我们可以非常容易地通过Dubbo来构建分布式服务,并根据自己实际业务应用场景来选择合适的集群容错模式,这个对于很多应用都是迫切希望的,只需要通过简单的配 ...

  4. win xp安装

    Windows XP with sp3 VOL 微软原版下载: zh-hans_windows_xp_professional_with_service_pack_3_x86_cd_vl_x14-74 ...

  5. 016 Java中的动态代理

    作者:nnngu GitHub:https://github.com/nnngu 博客园:http://www.cnblogs.com/nnngu 简书:https://www.jianshu.com ...

  6. MT【120】保三角函数

    评:1.这里处理第三个函数时用到$ab-a-b=(a-1)(b-1)-1$是处理$ab,a+b$之间加减的常见变形. 2.第二个函数$g(x)=sinx,x\in(0,\frac{5\pi}{6})$ ...

  7. KMP之Z-function (扩展kmp)

    http://codeforces.com/blog/entry/3107 // s[0, ..., n-1], z[0] = 0// z[i] is the length of the longes ...

  8. 【刷题】BZOJ 2346 [Baltic 2011]Lamp

    Description 2255是一个傻X,他连自己家灯不亮了都不知道. 某天TZ大神路过他家,发现了这一情况, 于是TZ开始行侠仗义了. TZ发现是电路板的问题, 他打开了电路板,发现线路根本没有连 ...

  9. Linux下的bash对拍

    下面是Linux下的bash对拍程序: #!/bin/bash t=0 //数据组数 while true; do let "t=$t + 1" echox printf $t / ...

  10. 使用msbuild.exe绕过应用程序白名单(多种方法)

      一.MSbuild.exe简介 Microsoft Build Engine是一个用于构建应用程序的平台.此引擎也被称为msbuild,它为项目文件提供一个XML模式,该模式控制构建平台如何处理和 ...