为什么我的应用程序在AppHarbor上运行时表现不同

本文关键字:运行时 我的 应用程序 AppHarbor 为什么 | 更新日期: 2023-09-27 17:59:50

我正在开发一个wcf RESTful web服务,该服务使用实体框架和代码优先来管理数据库,由AppHarbor中的SQL Server插件托管。现在,如果我使用启动IIS以托管应用程序的Visual Studio调试在本地运行我的应用程序,那么一切都可以完美运行。但是,如果我测试在AppHarbor中部署的服务(没有错误),一切都会出错,我会收到一个400坏请求。这是http响应中的堆栈跟踪:

at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
at    System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
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__DisplayClass7.<GetResults>b__5()
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.Execute(MergeOption mergeOption)
at System.Data.Entity.Core.Objects.DataClasses.EntityReference`1.Load(MergeOption mergeOption)
at System.Data.Entity.Core.Objects.DataClasses.RelatedEnd.DeferredLoad()
at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)
at System.Data.Entity.Core.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7`2.<GetInterceptorDelegate>b__2(TProxy proxy, TItem item)
at System.Data.Entity.DynamicProxies.UserCloudConn_100557DBEEC4B39F64FD7786B8E2F4080B576D2C357C3C1161822268F4233178.get_cloud()
at CloudStorageManager.MainService.GetActiveServices(UserCredential data) in d:'temp'inywl51q.z0c'input'DropboxWebService'Services'MainService.svc.cs:line 870
at CloudStorageManager.MainService.GetAvailableServices(UserCredential data) in d:'temp'inywl51q.z0c'input'DropboxWebService'Services'MainService.svc.cs:line 943
at SyncInvokeGetAvailableServices(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.ProcessMessage41(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

例如,这是我的一段代码,它给出了appharbor问题:

var cloudsConn = (from c in context.UserCloudConn where user.id == c.userId select c);
foreach (UserCloudConn conn in cloudsConn)
{
    list.Add(conn.cloud.name); // HERE THE STACK TRACE GIVE ME AN ERROR. LINE 870
}

这是我使用的型号:

public class DatabaseEntities : DbContext
{
    public DatabaseEntities() : base("name=DatabaseConnectionString") { }
    public DbSet<User> Users { get; set; }
    public DbSet<Cloud> Clouds { get; set; }
    public DbSet<UserCloudConn> UserCloudConn { get; set; }
}
public class User
{
    [Key]
    [Column(Order = 1)]
    public int id { get; set; }
    [Key]
    [Column(Order = 2)]
    public string email { get; set; }
    public string password { get; set; }
    public string accessToken { get; set; }
    public string name { get; set; }
    public string surname { get; set; }
    public virtual ICollection<UserCloudConn> userCloudConn { get; set; } // ogni user ha n tuple in UserCloudConn
}
public class Cloud
{
    [Key]
    public int id { get; set; }
    public string name { get; set; }
    public string appKey { get; set; }
    public string appSecret { get; set; }
    public virtual ICollection<UserCloudConn> userCloudConn { get; set; } // ogni cloud ha n tuple in UserCloudConn
}
public class UserCloudConn
{
    [Key]
    [Column(Order = 1)] 
    public int userId { get; set; }
    [Key]
    [Column(Order = 2)] 
    public int cloudId { get; set; }
    public string accessToken { get; set; }
    public string accessSecret { get; set; }
    public string email { get; set; }
    public string password { get; set; }
    public string refreshToken { get; set; }
    public int expireIn { get; set; }
    public string tokenType { get; set; }
    public string timeStamp { get; set; }
    public virtual Cloud cloud { get; set; } // Ogni tupla in UserCloudConn è associata ad un cloud
    public virtual User user { get; set; } // Ogni tupla in UserCloudConn è associata ad uno User
}

编辑:我做了一些测试,发现问题是当我使用类UserCloudConn的云属性时,它是虚拟的。我想我应该用linq做另一个查询,从我的数据库中获取云,但为什么这在appharbor上不起作用,但在本地机器上起作用????

为什么我的应用程序在AppHarbor上运行时表现不同

我有这个错误,因为在本地连接字符串中,我将MultipleActiveResulSet添加为true,但在AppHarbor SQL服务器设置中,我没有激活它。所以这是我的错。现在它起作用了。感谢