简体   繁体   中英

Web service with Entity framework connection

I have created a web site in C# 2010 with Entity framework, in the same i have also added one web service and deployed the same on server.

Now my web site is working good ,but when i open web service the asmx page will open up but the method which require database connection is not working.

I have used project dll in my web service for connection.

Now every time when i run web service method which connect to database it show me the message PAGE NOT FOUND.

Please suggest

Exception details:

System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: 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)

The web.config file needs the connection string for the Model, plus some bits and pieces. Make sure that it contains the following, and change the connection string to have your own server, database, and authentication details:

  <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=&quot;Server=Your Server Name;Database=Your Database Name;Integrated Security=SSPI;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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>

These are probably best copied from yout web site web.config file, rather than from the above, but you need the three sections:

<ConfigSections> , <connectionStrings> , and <entityFramework>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM