背景:

之前项目使用的是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. SQL语句中的output用法

    private void button2_Click(object sender, RoutedEventArgs e) { using (SqlConnection conn = new SqlCo ...

  2. 配置ssh免密码登入

    首先要设置好主机名hostnamectl,然后编辑文件/etc/hosts 192.168.43.9 node0 192.168.43.10 node1 192.168.43.11 node2     ...

  3. Alpha阶段博客链接

    博客链接 团队项目启程篇章:http://www.cnblogs.com/liuliudashun/p/5968194.html 团队项目开发篇章1:http://www.cnblogs.com/li ...

  4. javascript获取当前日期和时间

    ){ ){ _time = year+"-"+month+"-"+date+" "+hour+":"+minu+&quo ...

  5. mybatis映射文件的使用(一),工程目录结构、源代码和数据库

    代码开发环境 开发工具为IDEA 工程构建方式为maven 数据库为mysql 5.7.20 mybatis版本为 3.1.1 mysql-connect-java jar包版本为 5.1.34 数据 ...

  6. 【译】关于vertical-align你应知道的一切

    原文地址:Vertical-Align: All You Need To Know 通常我们需要垂直对齐并排的元素. CSS提供了一些可实现的方法:有时我用浮动float来解决,有时用position ...

  7. 第219天:Angular---过滤器

    在Angular中,过滤器的功能主要是格式化数据表达式,且可以自定义过滤器.作用域(scope)主要服务于页面模板,在控制器和页面中起桥梁作用,保存模板中的数据对象,为模板中的元素提供方法和属性. 一 ...

  8. Visual Categorization with Bags of Keypoints

    1.Introduction and backgrounds 作为本周的论文之一,这是一篇bag of features的基本文章之一,主要了解其中的基本思路,以及用到的基本技术,尽量使得细节更加清楚 ...

  9. 小Z的袜子(hose) HYSBZ - 2038 (莫队算法)

    原文地址:http://hzwer.com/2782.html 「BZOJ2038」[2009国家集训队] 小Z的袜子(hose) 2014年4月26日13,34721 Description 作为一 ...

  10. C/C++缓冲区刷新问题

    参考链接 参考链接2 Buffers are normally maintained by the operating system, which determines the optimal tim ...