实体框架连接字符串错误

实体框架连接字符串错误

本文介绍了postgresql(.NET-MVC)实体框架连接字符串错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从实体框架创建了数据库优先,框架在我的web.config中创建了连接字符串,如

I have created database-first from entity framework,the framework created connection string in my web.config like

<connectionStrings>
    <add name="projeEntities" connectionString="metadata=res://*/Models.EntityFrameworks.ProjeModel.csdl|res://*/Models.EntityFrameworks.ProjeModel.ssdl|res://*/Models.EntityFrameworks.ProjeModel.msl;provider=Npgsql;provider connection string="Host=127.0.0.1;Database=proje;Username=postgres;Password=sdt2018; Persist Security Info=True"" providerName="System.Data.EntityClient" />
  </connectionStrings>



但是这不起作用,visual studio给出了这个错误


but this is not working ,visual studio gave this error

System.Data.Entity.Core.EntityException: 'The underlying provider failed on ConnectionString.'



当我更改web.config时,如


When I change web.config like

<add name="projeEntities"
           connectionString="Server=127.0.0.1;Database=proje;User Id=postgres;Password=sdt2018;"
           providerName="Npgsql" />



visual studio给出了代码第一个错误,但我正在开发数据库。你能帮帮我吗?



我尝试了什么:



我我试图改变连接字符串,但它没有帮助我


visual studio gave code first error but I am working on database first. Can you help me?

What I have tried:

I have tried to change connection string but it didnot help me

推荐答案

<add name="DefaultConnection" connectionString="Data Source=servername;Initial Catalog=databasename;Persist Security Info=True;User ID=sa;Password=yourpassword" providerName="System.Data.SqlClient"/>

<add name="AEntities" connectionString="metadata=res://*/EntityModel.AModel.csdl|res://*/EntityModel.AModel.ssdl|res://*/EntityModel.AModel.msl;provider=System.Data.SqlClient;provider connection string="data source=servername;initial catalog=databasename;persist security info=True;user id=sa;password=yourpassword;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>


<connectionStrings>
  <add name="projeEntities" connectionString="metadata=res://*/Models.EntityFrameworks.ProjeModel.csdl|res://*/Models.EntityFrameworks.ProjeModel.ssdl|res://*/Models.EntityFrameworks.ProjeModel.msl;provider=Npgsql;provider connection string="Host=127.0.0.1;Database=proje;Username=postgres;Password=sdt2018;"" providerName="System.Data.EntityClient" />
</connectionStrings>

我做了这个和版本检查,然后它工作

I did this and version check,then it works


这篇关于postgresql(.NET-MVC)实体框架连接字符串错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 15:15