我需要帮助配置通过 EF 访问 SQL 数据库的 WCF 服务。当我通过 Visual Studio 在本地启动它时,该服务运行良好,但是当我将它部署到另一台服务器并通过我的客户端应用程序访问它时,我不断收到“{”从数据库获取提供程序信息时发生错误。这可能是由 Entity Framework 使用不正确的连接字符串引起的。检查内部异常以获取详细信息并确保连接字符串正确。“}”错误。
在将服务发布到服务器之前,我的连接字符串是:
<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;
}
有什么建议么?内部异常也是空的。