运行sqlcmd时,TFS2010版本中的InvokeProcess不会冒出错误

时间:2011-11-29 19:04:28

标签: xaml tfs2010

我正在使用InvokeProcess任务来运行SqlCmd,以便对数据库执行sql脚本。但是,如果在sql脚本中遇到错误,则不会引发任何错误,并且根据XAML,构建状态不会设置为false。可能会发生什么? 以下是代码段:

<mtbwa:InvokeProcess Arguments="[&quot;-b -S server1\dev -U sa -P password -i &quot;&quot;&quot; + SourcesDirectory + &quot;\DatabaseScripts\conversion.sql&quot;&quot;&quot;]" DisplayName="Run Conversion SQL" FileName="c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe" sap:VirtualizedContainerService.HintSize="464,384" Result="[ExitCode]" WorkingDirectory="[SourcesDirectory]">
<mtbwa:InvokeProcess.ErrorDataReceived>
    <ActivityAction x:TypeArguments="x:String">
        <ActivityAction.Argument>
        <DelegateInArgument x:TypeArguments="x:String" Name="errOutput" />
        </ActivityAction.Argument>
        <Sequence sap:VirtualizedContainerService.HintSize="222,208">
            <sap:WorkflowViewStateService.ViewState>
            <scg:Dictionary x:TypeArguments="x:String, x:Object">
            <x:Boolean x:Key="IsExpanded">True</x:Boolean>
            </scg:Dictionary>
            </sap:WorkflowViewStateService.ViewState>
            <mtbwa:WriteBuildError DisplayName="VSDBCMD Error" sap:VirtualizedContainerService.HintSize="200,22" Message="[errOutput]" />
            <mtbwa:SetBuildProperties DisplayName="Set build to failed" sap:VirtualizedContainerService.HintSize="200,22" PropertiesToSet="Status" Status="[Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed]" />
        </Sequence>
    </ActivityAction>
</mtbwa:InvokeProcess.ErrorDataReceived>
<mtbwa:InvokeProcess.OutputDataReceived>
    <ActivityAction x:TypeArguments="x:String">
        <ActivityAction.Argument>
        <DelegateInArgument x:TypeArguments="x:String" Name="stdOutput" />
        </ActivityAction.Argument>
        <mtbwa:WriteBuildMessage sap:VirtualizedContainerService.HintSize="222,22" Message="[stdOutput]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
    </ActivityAction>
</mtbwa:InvokeProcess.OutputDataReceived>
<sap:WorkflowViewStateService.ViewState>
    <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsPinned">False</x:Boolean>
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
    </scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>

1 个答案:

答案 0 :(得分:0)

事实证明,sqlcmd不会返回错误代码。我决定解析命令输出,查找失败字符串,如果找到则抛出异常。这是片段:

<mtbwa:InvokeProcess Arguments="[&quot;-b -S myServer\dev -U sa -P password -i &quot;&quot;&quot; + SourcesDirectory + &quot;\DatabaseScripts\conversion.sql&quot;&quot;&quot;]" DisplayName="Run Conversion SQL" FileName="c:\Program Files\Microsoft SQL Server\100\Tools\Binn\sqlcmd.exe" sap:VirtualizedContainerService.HintSize="464,599" Result="[ExitCode]" WorkingDirectory="[SourcesDirectory]">
<mtbwa:InvokeProcess.ErrorDataReceived>
    <ActivityAction x:TypeArguments="x:String">
    <ActivityAction.Argument>
    <DelegateInArgument x:TypeArguments="x:String" Name="errOutput" />
    </ActivityAction.Argument>
    <Sequence sap:VirtualizedContainerService.HintSize="222,208">
    <sap:WorkflowViewStateService.ViewState>
    <scg:Dictionary x:TypeArguments="x:String, x:Object">
    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
    </scg:Dictionary>
    </sap:WorkflowViewStateService.ViewState>
    <mtbwa:WriteBuildError DisplayName="VSDBCMD Error" sap:VirtualizedContainerService.HintSize="200,22" Message="[errOutput]" />
    <mtbwa:SetBuildProperties DisplayName="Set build to failed" sap:VirtualizedContainerService.HintSize="200,22" PropertiesToSet="Status" Status="[Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed]" />
    </Sequence>
    </ActivityAction>
</mtbwa:InvokeProcess.ErrorDataReceived>
<mtbwa:InvokeProcess.OutputDataReceived>
    <ActivityAction x:TypeArguments="x:String">
        <ActivityAction.Argument>
        <DelegateInArgument x:TypeArguments="x:String" Name="stdOutput" />
        </ActivityAction.Argument>
        <Sequence sap:VirtualizedContainerService.HintSize="222,237">
        <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
        </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <mtbwa:WriteBuildMessage sap:VirtualizedContainerService.HintSize="200,22" Importance="[Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High]" Message="[stdOutput]" mva:VisualBasic.Settings="Assembly references and imported namespaces serialized as XML namespaces" />
        <If Condition="[stdOutput.Contains(&quot;The statement has been terminated.&quot;)]" sap:VirtualizedContainerService.HintSize="200,51">
        <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">False</x:Boolean>
        <x:Boolean x:Key="IsPinned">False</x:Boolean>
        </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <If.Then>
        <Sequence sap:VirtualizedContainerService.HintSize="281,208">
        <sap:WorkflowViewStateService.ViewState>
        <scg:Dictionary x:TypeArguments="x:String, x:Object">
        <x:Boolean x:Key="IsExpanded">True</x:Boolean>
        </scg:Dictionary>
        </sap:WorkflowViewStateService.ViewState>
        <mtbwa:SetBuildProperties DisplayName="Set build to failed" sap:VirtualizedContainerService.HintSize="200,22" PropertiesToSet="Status" Status="[Microsoft.TeamFoundation.Build.Client.BuildStatus.Failed]" />
        <Throw Exception="[New Exception(&quot;Conversion.sql failed&quot;)]" sap:VirtualizedContainerService.HintSize="200,22" />
        </Sequence>
        </If.Then>
        </If>
        </Sequence>
    </ActivityAction>
</mtbwa:InvokeProcess.OutputDataReceived>
<sap:WorkflowViewStateService.ViewState>
    <scg:Dictionary x:TypeArguments="x:String, x:Object">
    <x:Boolean x:Key="IsPinned">False</x:Boolean>
    <x:Boolean x:Key="IsExpanded">True</x:Boolean>
    </scg:Dictionary>
</sap:WorkflowViewStateService.ViewState>