[英]WCF and EntityFramework error in IIS 8 The server encountered an error processing the request
I'm new to WCF ,I Developed a simple WCF service Application in which i added entityframework data model. 我是WCF的新手,我开发了一个简单的WCF服务应用程序,在其中添加了EntityFramework数据模型。 I have a method which return one field of a table from database.
我有一种方法可以从数据库中返回表的一个字段。 I'm working on visual studio 2013 and sql server 2012 on windows 8. When i run it in IISExpress everything is ok.But when i run it from iis ,it display the below error:
我正在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)
This is My Service1.svc.cs 这是我的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;
}
I Searched alot and did what they say here but noting changed. 我搜索了很多,并做了他们在这里所说的,但注意有所改变。 any help really appreciate.
任何帮助都非常感谢。 best regards.
最好的祝福。
Most likely it's permission issue. 最有可能是权限问题。
1) if you connecting to local DB, here is answer MSSQL Error 'The underlying provider failed on Open' 1)如果您连接到本地数据库,则答案为MSSQL错误“底层提供程序在打开时失败”
2) if you connecting to remote server, check firewall settings on DB server 2)如果您连接到远程服务器,请检查数据库服务器上的防火墙设置
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.