如何使用EntityFramework连接到SQL Server Express [英] How to connect to SQL Server Express using EntityFramework

查看:282
本文介绍了如何使用EntityFramework连接到SQL Server Express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在网络和Stack Overflow上找到有关此信息的信息,但没有一个响应可以帮助我解决我的问题。

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

我正在使用C#和SQL Server。我正在使用现有项目的代码,该项目连接到SQL Server实例来管理数据。此项目使用EntityFramework。

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.

现在我想使用SQL Server的本地实例,正是SQL Server Express,用于开发目的。但是我不知道如何连接到这个本地的实例。

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.

连接到远程SQL Server可以完美地运行,使用这个连接字符串:

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" />

它不起作用。

我尝试将源放在MAC\PROJECT中,它不会改变任何东西。使用udl文件解决方法测试连接参数完全可以同时使用MAC\PROJECT和.\PROJECT和正确的凭据。

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?

推荐答案

发布此问题后,我发现答案....旧的连接字符串给出一个端口数字,连接到本地实例时不需要。

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.

这篇关于如何使用EntityFramework连接到SQL Server Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆