.NET控制台应用程序连接字符串转换错

时间:2018-03-28 15:13:10

标签: c# .net asp.net-mvc azure

我正在将一个控制台应用程序作为webjob上传到我在azure上的应用服务。我已经卸载了应用程序,并告诉它在csproj中包含一个发布配置:

<Content Include="App.config" />
<Content Include="App.Debug.config">
  <DependentUpon>App.config</DependentUpon>
</Content>
<Content Include="App.Release.config">
  <DependentUpon>App.config</DependentUpon>
</Content

最后还有这个:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
<!-- Generate transformed app config in the intermediate directory -->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)  $(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
  <AppConfigWithTargetPath Remove="app.config" />
  <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
    <TargetPath>$(TargetFileName).config</TargetPath>
  </AppConfigWithTargetPath>
</ItemGroup>

在我的本地计算机上,连接字符串是:

<connectionStrings>
<add name="Default1" connectionString="data source=.\SQLEXPRESS;initial catalog=Default1;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>

在App.Release.Config中我有这个:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="Default1"  connectionString="Server=tcp::NewApplication.database.windows.net,1433;Initial Catalog=NewApplication;Persist Security Info=False;User ID=NewApplicationadmin;Password=testing;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>

控制台应用程序在我的本地计算机上运行正常,我在网络应用程序上进行转换的方式完全相同。

然而,当我上传它并将其作为webjob运行时,它在日志中无法提供此错误:

Unhandled Exception: System.Data.Entity.Core.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. ---> System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.

在这种情况下会导致什么?

0 个答案:

没有答案