[英]Web service with Entity framework connection
我已經在C#2010中使用Entity Framework創建了一個網站,同樣,我還添加了一個Web服務並將其部署在服務器上。
現在我的網站運行良好,但是當我打開Web服務時,asmx頁面將打開,但是需要數據庫連接的方法無法正常工作。
我在網絡服務中使用了項目dll進行連接。
現在,每次我運行連接到數據庫的Web服務方法時,都會顯示消息PAGE NOT FOUND。
請建議
異常詳細信息:
System.Data.EntityException:基礎提供程序在打開時失敗。 ---> System.Data.SqlClient.SqlException:建立與SQL Server的連接時發生與網絡相關或特定於實例的錯誤。 服務器未找到或無法訪問。 驗證實例名稱正確,並且已將SQL Server配置為允許遠程連接。 (提供者:命名管道提供程序,錯誤:40-無法打開與SQL Server的連接)
web.config文件需要模型的連接字符串以及一些零碎的片段。 確保它包含以下內容,然后更改連接字符串以擁有自己的服務器,數據庫和身份驗證詳細信息:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="YourModelNameHere" connectionString="metadata=res://*/RCMarketModel.csdl|res://*/YourModelNameHere.ssdl|res://*/YourModelNameHere.msl;provider=System.Data.SqlClient;provider connection string="Server=Your Server Name;Database=Your Database Name;Integrated Security=SSPI;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
這些最好從您的網站web.config文件中復制,而不是從上面復制,但是您需要三個部分:
<ConfigSections>
, <connectionStrings>
和<entityFramework>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.