• 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=&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

  • 相关阅读:
    关于基础排序算法的思考--插入排序
    关于购物车的多层复选全选
    随便写写
    第一篇小博文
    C# 遍历目录下所有文件方法
    C#驱动MongoDB官方中查询条件Query用法
    mongodb 修改远程连接
    Python 爬虫练习低调163疫情数据辽宁地图
    jquery easyui datagrid drop事件执行顺序
    https request报错 ServicePointManager.SecurityProtocol 搞定
  • 原文地址:https://www.cnblogs.com/LeimOO/p/3637496.html
Copyright © 2020-2023  润新知