title: ReportViewer - Subreport processing impersonation context
body: <p>I have a reportviewer report with a sub report. Running locally the report works fine, when i deploy to another server a get a SQL access denied error for the local user on the remote machine. eg</p>
  
  <p>access denied for servername\servername$</p>
  
  <p>i have a feeling this is due to me firing a SQL command to get the data required for the sub report and when deployed on the server the report viewer is firing this command and becuase all of my connection strings are using integrated security (for security reasons) its then not got the correct impersonation context.</p>
  
  <p>My database access class is in a different assembly than the reporting assembly, both of these assemblies are referenced from the web application</p>
  
  <p>It seems the report viewer is calling the sub report processing event when it needs to get the data for the sub report. The web application impersonates a user when it runs but the sub report processing event does not use this specified user. Instead perhaps the local system account instead, and as the connection strings are using integrated security the local system account does not have access to the database which is on another server.</p>
  
  <p>anyone else have this problem?</p>
  
  <p>here is the code for my report page</p>
  
  <pre><code>/// &lt;summary&gt;
          /// Page Load
          /// &lt;/summary&gt;
          /// &lt;param name="sender"&gt;&lt;/param&gt;
          /// &lt;param name="e"&gt;&lt;/param&gt;
          protected void Page_Load( object sender, EventArgs e )
          {
              try
              {
                  if ( !Page.IsPostBack )
                  {
                      Reporting.Common.SetReportEmbeddedResource( this.ReportViewer1, "xxx.Web.WAP.Reporting.Reports.ApprovalRouteHeader.rdlc" );
  
                      this.ReportViewer1.LocalReport.DataSources.Add(
                          new Microsoft.Reporting.WebForms.ReportDataSource(
                              "CostDept",
                            Reporting.Repositories.ApprovalRoute.GetHeaderApprovalRouteList() ) );
  
                      this.ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
                      this.ReportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WebForms.SubreportProcessingEventHandler( LocalReport_SubreportProcessing );
  
                      this.ReportViewer1.LocalReport.Refresh();
                  }
              }
              catch ( Exception ex )
              {
                  ErrorLogging.LogError( ex );
              }
          }
  
          /// &lt;summary&gt;
          /// Loads the sub report
          /// &lt;/summary&gt;
          /// &lt;param name="sender"&gt;object&lt;/param&gt;
          /// &lt;param name="e"&gt;args&lt;/param&gt;
          protected void LocalReport_SubreportProcessing( object sender, Microsoft.Reporting.WebForms.SubreportProcessingEventArgs e )
          {
              try
              {
                  e.DataSources.Add(
                      new Microsoft.Reporting.WebForms.ReportDataSource(
                          "CostDept",
                          Reporting.Repositories.ApprovalRoute.GetDetailApprovalRouteList(
                          Convert.ToInt32( e.Parameters[ "AccountNumberID" ].Values[ 0 ] ),
                           Convert.ToInt32( e.Parameters[ "SageDatabaseID" ].Values[ 0 ] ),
                         Convert.ToInt32( e.Parameters[ "RequestingUserID" ].Values[ 0 ] ),
                          Convert.ToInt32( e.Parameters[ "ProjectID" ].Values[ 0 ] ),
                            Convert.ToInt32( e.Parameters[ "ProjectItemID" ].Values[ 0 ] ),
                          e.Parameters[ "DocumentType" ].Values[ 0 ].ToString() ) ) );
              }
              catch ( Exception ex )
              {
                  ErrorLogging.LogError( ex );
              }
          }
  </code></pre>