簡體   English   中英

IIS 8中的WCF和EntityFramework錯誤服務器在處理請求時遇到錯誤

[英]WCF and EntityFramework error in IIS 8 The server encountered an error processing the request

我是WCF的新手,我開發了一個簡單的WCF服務應用程序,在其中添加了EntityFramework數據模型。 我有一種方法可以從數據庫中返回表的一個字段。 我正在Windows 8上使用Visual Studio 2013和SQL Server2012。當我在IISExpress中運行它時,一切正常。但是,當我從iis運行它時,顯示以下錯誤:

Request Error
The server encountered an error processing the request. The exception message is
 'The  underlying provider failed on Open.'. See server logs for more details. The exception stack trace is:

at System.Data.Entity.Core.EntityClient.EntityConnection.Open() at
System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection() at   
System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, 
IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean  
releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery`1.
<>c__DisplayClassb.<GetResults>b__9() at 
System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 
operation) at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 
forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery`1.
<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0() at 
System.Lazy`1.CreateValue() at System.Lazy`1.LazyInitValue() at 
System.Data.Entity.Internal.LazyEnumerator`1.MoveNext() at 
WcfRestService.Service1.SelectRandomQuestion() at SyncInvokeSelectRandomQuestion(Object 
, Object[] , Object[] ) at 
System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] 
inputs, Object[]& outputs) at 
 System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc) 
 at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& 
rpc) at 
System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& 
rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean 
isOperationContextSet)

這是我的Service1.svc.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Data.Services.Providers;
using System.Text;

namespace WcfRestService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class     name "Service1" in code, svc and config file together.
// NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
[System.ServiceModel.ServiceBehavior(IncludeExceptionDetailInFaults = true)] 

public class Service1 : EntityFrameworkDataService<CollaborationDBEntities>, IService1
{

    public string SelectRandomQuestion()
    {
        using (CollaborationDBEntities db = new CollaborationDBEntities())
        {
            var q = from questions in db.QuestionTable
                    select questions.QText;
            List<string> list = new List<string>();
            foreach (var item in q)
            {
                list.Add(item);
            }
            Random random = new Random();
            int selectedIndex = random.Next(0, list.Count);

            return list[selectedIndex];
        }
    }
    public string AddNewUser(string userName, string fName, string lName, string email, string imei)
    {
        using (CollaborationDBEntities db = new CollaborationDBEntities())
        {
            UserTable userObject = new UserTable() { UserName = userName, UserFName = fName, UserLName = lName, UserNumber = imei };
            db.UserTable.Add(userObject);
        }

        return null;
    }

我搜索了很多,並做了他們在這里所說的但注意有所改變。 任何幫助都非常感謝。 最好的祝福。

最有可能是權限問題。

1)如果您連接到本地數據庫,則答案為MSSQL錯誤“底層提供程序在打開時失敗”

2)如果您連接到遠程服務器,請檢查數據庫服務器上的防火牆設置

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM