实体框架 4 底层提供程序在打开时失败
我正在尝试连接到数据库,但出现此异常:
A network-related or instance-specific error occurred while establishing a connection to
SQL Server. The server was not found or was not accessible. Verify that the instance name
is correct and that SQL Server is configured to allow remote connections.
(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
我用谷歌搜索了很多,但找不到答案。
这是我的配置:
我使用 MS SQL Server 2008 Express。 Sql Server 和 Sql Server Browser 都使用我的帐户(我是管理员)。我还使用过本地系统和本地服务。没有成功。
这是我在 app.config 中的连接字符串:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="EventManagerEntities" connectionString="metadata=res://*/Entities.RelationModel.csdl|res://*/Entities.RelationModel.ssdl|res://*/Entities.RelationModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=martijn-laptop\sql2008;Initial Catalog=EventManager;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
我也尝试过使用 sql server 用户名和密码,但也没有成功。
我正在使用winform。我还能尝试什么?
当我检查 netstat -an 时,我得到这个:
TCP 0.0.0.0:1433 0.0.0.0:0 LISTENING
TCP [::]:1433 [::]:0 LISTENING
我认为这是不正确的,对吗?但我该如何设置它呢?
I am trying to connect to the database but I am getting this exception:
A network-related or instance-specific error occurred while establishing a connection to
SQL Server. The server was not found or was not accessible. Verify that the instance name
is correct and that SQL Server is configured to allow remote connections.
(provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I've googled a lot, but I could not find the answer.
Here's my configuration:
I use MS SQL Server 2008 Express. Both Sql Server and Sql Server Browser use my account (I am an administrator). I've also used local system and local service. Without success.
Here is my connectionstring in app.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="EventManagerEntities" connectionString="metadata=res://*/Entities.RelationModel.csdl|res://*/Entities.RelationModel.ssdl|res://*/Entities.RelationModel.msl;provider=System.Data.SqlClient;provider connection string="Data Source=martijn-laptop\sql2008;Initial Catalog=EventManager;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient"/>
</connectionStrings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
I've also tried to use the sql server username and password, also without success.
I am using winforms. What else can I try?
When I check netstat -an I get this:
TCP 0.0.0.0:1433 0.0.0.0:0 LISTENING
TCP [::]:1433 [::]:0 LISTENING
I don't think this is correct, right? But how do I set it right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它找不到实例/服务器。 Telnet第1433号或martijn-laptop\sql2008配置的端口,验证其可访问
It cannot find instance/server. Telnet the 1433th or the configured port of martijn-laptop\sql2008 to verify its accessible
进入 SQL Server 配置管理器并确保在“SQL Server 网络配置”>“SQL Server 网络配置”下启用了要使用的协议。 《Sql2008 协议》
Go into the SQL Server Configuration Manager and make sure you have the protocols you want to use enabled under "SQL Server Network Configuration" > "Protocols for Sql2008"
从错误来看,似乎存在数据库连接问题。假设此解决方案已在其他地方运行,您是否已设置并连接到不同的数据库?
请验证使用 edmx 生成的代码是否具有正确的默认数据库连接名称,或者您要覆盖它:
或者 EF 的正确系统税是什么。
From the error it seem like there is connectivity to database issue. Assuming this solution has been working elsewhere have you setup and connected to a different database?
Is so validate that the code generated with edmx has the correct default database connection name or that you are overriding it:
Or whatever the correct systax for EF is.