How to connect to SQL Server Express using EntityFramework

谁都会走 提交于 2019-12-13 02:28:45

问题


I tried to find information about this on the web and Stack Overflow, but none of the responses could help me solving my problem.

I'm working with C# and SQL Server. I'm using code from an existing project, which project connects to an SQL Server instance to manage data. This project uses EntityFramework.

Now I want to use a local instance of SQL Server, precisely SQL Server Express, for development purpose. But I can't figure out how to connect to this local instance.

Connecting to the remote SQL Server works perfectly, using this connection string:

<add name="ProjectEntities" connectionString="metadata=res://*/Project.Project.csdl|res://*/Project.Project.ssdl|res://*/Project.Project.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=111.111.111.666\(local), 1433;initial catalog=PROJECT;persist security info=True;user id=user;password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

But if I modify it to use my local instance:

<add name="ProjectEntities" connectionString="metadata=res://*/Project.Project.csdl|res://*/Project.Project.ssdl|res://*/Project.Project.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\PROJECT, 1433;initial catalog=PROJECT;persist security info=True;user id=user;password=password;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

it doesn't work.

I tried with putting the source in "MAC\PROJECT" also, it does not change anything. Using the udl file workaround to test connection parameters is totally OK both with "MAC\PROJECT" and ".\PROJECT" and the right credentials.

I can't figure out why my project connect to the database perfectly using the remote server but not the local one. Am I missing something?


回答1:


Right after posting this question I found the answer.... The old connection string gives a port number, which is not needed when connecting to the local instance.



来源:https://stackoverflow.com/questions/33362657/how-to-connect-to-sql-server-express-using-entityframework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!