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

时间:2014-04-24 18:06:55

标签: c# wcf appharbor

我正在开发一个wcf RESTful Web服务,该服务使用Entity Framework和Code-First来管理由AppHarbor中的SQL Server插件托管的数据库。现在,如果我通过使用启动IIS来托管应用程序的Visual Studio调试在本地运行我的应用程序,一切都运行良好。但是,如果我在AppHarbor中测试部署的服务(没有错误),一切都会出错,我收到400 Bad Request。 这是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)

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

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上运行但是它适用于本地机器????

1 个答案:

答案 0 :(得分:1)

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