实体框架“底层提供程序在打开时失败” - 卡西尼号与 IIS
我有一项使用 EF 从 SQL 数据库检索数据的服务。
EF 模型位于类库中。在类库中,连接配置为:
<add name="APIC2CEntities"
connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
该类库由 WCF 服务项目引用。在 webconfig 中,我通过以下方式控制 EF 连接:
<add name="APIC2CEntities"
connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
当我的服务在 Cassini 中运行时,可以正确检索数据。当服务在 IIS (Windows XP) 下运行时,连接失败并出现以下异常:
底层提供商打开失败
,内部异常告诉我:
{“与 SQL Server 建立连接时发生网络相关或特定于实例的错误。找不到服务器或无法访问服务器。请验证实例名称是否正确以及 SQL Server 是否配置为允许远程连接。(提供程序:Named Pipes Provider,错误:40 - 无法打开到 SQL Server 的连接)"}
我了解 Cassini 正在我的登录帐户下运行,并且 IIS 正在 IUSR_MYMACHINE 帐户下运行,但是我的联系不受信任,所以这不应该很重要...
IIS 和 Cassini 之间如何以不同的方式操纵或控制 EF 连接?
谢谢,
标记
I have a service that uses EF to retrieve data from a SQL database.
The EF model is in a class library. In the class library the connection is configured as:
<add name="APIC2CEntities"
connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
This class library is referenced by a WCF service project. In webconfig I control the EF connection with:
<add name="APIC2CEntities"
connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="data source=MYSERVER;initial catalog=MYDB;user id=MYUSER;password=THEPASSWORD;multipleactiveresultsets=True;App=EntityFramework""
providerName="System.Data.EntityClient" />
When my service is running in Cassini the data is retrieved correctly. When the service is running under IIS (Windows XP) the connection fails with the following exception:
The underlying provider failed on Open
with an inner exception telling me:
{"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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)"}
I understand that Cassini is running under my logged in account, and that IIS is running under the IUSR_MYMACHINE account, but my connection is not trusted, so this shouldn't matter...
How else might an EF connection be manipulated or controlled differently between IIS and Cassini?
Thanks,
Mark
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这次我们的解决方案是强制连接使用 tcp(在连接字符串中使用
data source=tcp:MyServer
)并在 SQL 框上启用 TCP(哎呀!)..我仍然没有了解 Cassini 会话如何能够在 IIS 会话未建立的情况下建立连接 :-S
Mark
Our resolution on this occasion was to force the connection to use tcp (using
data source=tcp:MyServer
in the connection string) and enabling TCP on the SQL box (oops!)..I still have no idea how the Cassini session was able to establish connection where the IIS session was not :-S
Mark
我认为问题仍然出在连接字符串上。如果您确定,请执行以下步骤并测试
I think the issue is still in connection string. If you are sure please do the following steps and test
此解决方案适用于在部署Windows应用程序时遇到此问题的人,
我知道这已经晚了,但这可能对将来的某人有用,在我的场景中,纯粹是我开发了一个Windows的连接字符串问题使用实体框架(数据库优先方法)的应用程序并且我发布了它,代码在我的计算机上运行良好,但在客户端计算机上不起作用
此问题的原因:-
我更新了客户端计算机连接App.config 文件中的字符串,但这是错误的,如果这是一个 Windows 应用程序,那么它将不会读取来自 App.config 的连接字符串(对于已部署的计算机),它将从 .exe.config 文件中读取,
因此在部署后,我们需要更改“AppicationName”.exe.config 文件中的连接字符串
This solution is for someone facing this issue while deploying windows application,
I know this is late, but this maybe useful for someone in future, In my scenario, purely this is a connection string issue I developed a windows application using entity framework (DB First approach) and I published it, the code was worked fine on my machine, but it's not worked on the client machine
Reason for this issue:-
I updated the client machine connection string in App.config file, but this is wrong, if that is a windows application, then it will not read the connection string from App.config (For deployed machines), it will read from .exe.config file,
So after deployment, we need to change the connection string in "AppicationName".exe.config file