IIS中的WCF EntityFrameWork异常

时间:2013-02-04 18:24:04

标签: c# wcf entity-framework

我需要帮助配置通过EF访问SQL数据库的WCF服务。当我通过visual studio在本地启动它时,该服务运行正常,但是当我将其部署到另一台服务器并通过我的客户端应用程序访问它时,我不断收到“{”从数据库获取提供程序信息时发生错误。这可能是由实体框架使用不正确的连接字符串引起的。检查内部异常以获取详细信息,并确保连接字符串正确。“}”错误。

在将服务发布到服务器之前,

我的连接字符串是:

<configSections>
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
</entityFramework>
<connectionStrings>
  <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ECUWebUi-20121116095239;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-ECUWebUi-20121116095239.mdf" />
</connectionStrings>
发布后

我的连接字符串:

<configSections>
  <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
<connectionStrings>
  <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost; Integrated Security=SSPI; Initial Catalog=ECUWeb-Staging;User ID=user;Password=password" />
</connectionStrings>

这是对服务中EF上下文的调用:

public RegisterResponse Register(RegisterRequest request)
{
    EfDataAccessFactory factory = new EfDataAccessFactory(new DtoMapper());
    RegisterResponse response = new RegisterResponse();

    if (request.Computer.Exists())
    {
        factory.ComputerDataAccess.Update(request.Computer);
        response.Message = string.Format("{0} is already registered.", request.Computer.Name);
    }
    else
    {
        request.Computer = factory.ComputerDataAccess.Insert(request.Computer);
        response.Message = string.Format("{0} registered with id: {1}", request.Computer.Name, request.Computer.Id);
    }

    RegisterInstances(request);

    return response;
}

有什么建议吗?内部异常也为空。

1 个答案:

答案 0 :(得分:0)

修正了我必须添加:

<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=localhost;Initial Catalog=ECUWeb-Staging;User Id = user; Password = password" />
    <add name="EcuWeb.Data.EcuWebDataContext" connectionString="Data Source=localhost;Initial Catalog=ECUWeb-Staging; User Id = user; Password = password" providerName="System.Data.SqlClient" />

然后它没有问题。