【问题标题】:Can't access a database from a WCF Data Service hosted in an ASP NET App无法从托管在 ASP NET 应用程序中的 WCF 数据服务访问数据库
【发布时间】:2014-02-13 03:12:13
【问题描述】:

我构建了一个托管在 ASP NET 应用程序中的 WCF 数据服务,该数据服务提供对 SQL Server 数据库的访问。

我还构建了一个访问服务的应用,即通过服务访问SQL数据库。

我在 SQL Server 中为 NT Authority\Network Service 创建了一个登录名,默认架构为 dbo。

(其实我是为NT Authority\Servicio de red创建的,Network Service是英文的“Servicio de red”)

我还在 Sql Server 中执行了以下操作:

ALTER LOGIN [NT AUTHORITY\Servicio de red] 
WITH DEFAULT_DATABASE=[MiniNorthwind]; 
GO
EXEC sp_addrolemember 'db_datareader', 'NT AUTHORITY\Servicio de red'
GO
EXEC sp_addrolemember 'db_datawriter', 'NT AUTHORITY\Servicio de red'
GO 

但是当我运行应用程序时,我收到以下错误>

当应用程序尝试迭代表时产生错误(第 48 行):

var customerOrders = new DataServiceCollection<Order>(ordersQuery);

会是什么?

拉斐尔

【问题讨论】:

    标签: asp.net wcf-data-services sql-server-2012-express


    【解决方案1】:

    您应该将DataServiceConfiguration 对象中的UseVerboseErrors 设置为您的服务类中传递给InitializeServicetrue

        public static void InitializeService(DataServiceConfiguration config)
        {
            // Don't let this go into prod
            config.UseVerboseErrors = true;
        }
    

    然后,您应该会收到比“处理此请求时发生错误”更有帮助的消息。

    注意:我总是把它们弄混,所以你可能还需要使用ServiceBehavior 属性将IncludeExceptionDetailInFaults 设置为true。您将此属性分配给您的服务类。

    [ServiceBehavior(IncludeExceptionDetailInFaults=true)]
    public class FooService : DataService<FooServiceContext>
    

    【讨论】:

      猜你喜欢
      • 2013-07-17
      • 1970-01-01
      • 2016-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-24
      相关资源
      最近更新 更多