MVC: Connection String
背景:
之前项目使用的是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="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;"" 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="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;"" 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="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;"" 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:
MVC: Connection String的更多相关文章
- ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB
您创建的MovieDBContext类负责处理连接到数据库,并将Movie对象映射到数据库记录的任务中.你可能会问一个问题,如何指定它将连接到数据库? 实际上,确实没有指定要使用的数据库,Entity ...
- [转]ASP.NET MVC 5 - 创建连接字符串(Connection String)并使用SQL Server LocalDB
您创建的MovieDBContext类负责处理连接到数据库,并将Movie对象映射到数据库记录的任务中.你可能会问一个问题,如何指定它将连接到数据库? 实际上,确实没有指定要使用的数据库,Entity ...
- MVC模式下unity配置,报错“No connection string named '**Context' could be found in the application config file”
写在前面: 第一次配置时好好的,后来第二次改到MVC模式,把依赖注入写成字典的单例模式时,由于新建的ORM(数据库映射模型EF),怎么弄都不用,一直报错"No connection str ...
- 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 ...
- 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 ...
- How to set China Azure Storage Connection String
Configure Visual Studio to access China Azure Storage Open Visual Studio 2012, Server Explorer Add n ...
- 转载 How to Encrypt connection string in web.config
转载原地址: https://chiragrdarji.wordpress.com/2008/08/11/how-to-encrypt-connection-string-in-webconfig/ ...
- 不支持的关键字:“provider connection string”报错信息及解决方案
今天在部署公司开发框架的时候 ,登录系统之后调用代办列表的时候就报错了 总线调用契约XX.Service.Contracts.IXXService上的GetXXCount方法时出错. Resoluti ...
- [转]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 ...
随机推荐
- javascript 组件化(转载)
这边只是很简陋的实现了类的继承机制.如果对类的实现有兴趣可以参考我另一篇文章javascript oo实现 我们看下使用方法: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...
- 1使用 vue-cli 搭建项目(cp)
http://www.cnblogs.com/wisewrong/p/6255817.html(copy:web) https://zhuanlan.zhihu.com/p/26183652(也很好) ...
- C 语言assert使用
1.assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义:#include <assert.h>void assert( i ...
- Centos7 pip 安装MySQLdb(mysql-python)出错
租了个阿里云的Centos7的ECS,需要使用pip安装MySQLdb模块.也就是mysql-python模块. 但是遇到问题 Collecting mysql-python Downloading ...
- .Net iTextSharp 生成pdf
拿别人例子 public ActionResult index() { var ms = new MemoryStream(); #region CreatePDF Document document ...
- 【Java】提取JSON数值时遇到数组集合时使用的K-V方式转换
1.实体类转换方法 参照文章:http://www.cnblogs.com/dflmg/p/6933811.html 2.K-V方法(此方法比较笨,但是没有办法,我现在不知道有没有相关的简单API,只 ...
- 【BZOJ4774】修路(动态规划,斯坦纳树)
[BZOJ4774]修路(动态规划,斯坦纳树) 题面 BZOJ 题解 先讲怎么求解最小斯坦纳树. 先明白什么是斯坦纳树. 斯坦纳树可以认为是最小生成树的一般情况.最小生成树是把所有给定点都要加入到联通 ...
- Mythological VI
Description 有\(1...n\)一共\(n\)个数.保证\(n\)为偶数. 小M要把这\(n\)个数两两配对, 一共配成\(n/2\)对.每一对的权值是他们两个数的和. 小M想要知道这\( ...
- cgroup限制内存
cgroup有个memory子系统,有两组对应的文件,一组带 memsw ,另一组不带. # docker ps -a # cd /sys/fs/cgroup/memory/docker/4b5619 ...
- mybatis.5.动态SQL
1.动态SQL,解决关联sql字符串的问题,mybatis的动态sql基于OGNL表达式 if语句,在DeptMapper.xml增加如下语句; <select id="selectB ...