SQL Server Reporting Service 报表自动部署 C#程序简化版

上次了解了可以通过Reporting Service 自带的 rs.exe 命令来批处理自动部署报表,仔细看了下部署脚本的运行模式,基本上是通过调用 ReportingService2005 来进行部署的,那么完全可以通过程序来调用,下面是一个简化版的自动部署工具。

ExpandedBlockStart.gif ContractedBlock.gif          /**/ /// <summary>
        
/// 在报表服务器上面部署指定的数据源connectionString
        
/// </summary>
        
/// <param name="rs">ReporterService2005</param>
        
/// <param name="name">数据源名称</param>
        
/// <param name="parentPath">部署目录</param>
        
/// <param name="extension">数据源连接类型:SQL, OLEDB, ODBC</param>
        
/// <param name="connectionString">连接串</param>

         public   static   void  CreateSampleDataSource(ReportingService2005 rs,  string  name,  string  parentPath,  string  extension,  string  connectionString)
ExpandedBlockStart.gifContractedBlock.gif        
{
            DataSourceDefinition dataSourceDefinition 
= new DataSourceDefinition();
            dataSourceDefinition.CredentialRetrieval 
= CredentialRetrievalEnum.Integrated;
            dataSourceDefinition.ConnectString 
= connectionString;
            dataSourceDefinition.Enabled 
= true;
            dataSourceDefinition.EnabledSpecified 
= true;
            dataSourceDefinition.Extension 
= extension;
            dataSourceDefinition.ImpersonateUser 
= false;
            dataSourceDefinition.ImpersonateUserSpecified 
= true;
            
//Use the default prompt string.
            dataSourceDefinition.Prompt = "";
            dataSourceDefinition.WindowsCredentials 
= false;

            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                rs.CreateDataSource(name, parentPath, 
true, dataSourceDefinition, null);
                Console.WriteLine(
"Data source {0} created successfully", name);
            }

            
catch (Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                Console.WriteLine(e.Message);
            }

        }


ExpandedBlockStart.gifContractedBlock.gif        
/**/ /// <summary>
        
/// 在报表服务器上面部署指定的报表reportName
        
/// </summary>
        
/// <param name="rs">ReporterService2005</param>
        
/// <param name="filePath">报表文件所在文件夹爱路径</param>
        
/// <param name="reportName">报表文件名称(不含.rdl),也即部署在ReportServer中的报表名称</param>
        
/// <param name="parentPath">部署目录</param>

         public   static   void  PublishReport(ReportingService2005 rs,  string  filePath,  string  reportName,  string  parentPath)
ExpandedBlockStart.gifContractedBlock.gif        
{
            
byte[] definition;
            
string ext = ".rdl";

            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                FileStream stream 
= File.OpenRead(filePath + reportName + ext);
                definition 
= new byte[stream.Length];
                stream.Read(definition, 
0, Convert.ToInt32(stream.Length));
                stream.Close();

                Warning[] warnings 
= rs.CreateReport(reportName, parentPath, true, definition, null);
                
if (warnings != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    
foreach (Warning warning in warnings)
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
{
                        Console.WriteLine(warning.Message);
                    }

                }

                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
{
                    Console.WriteLine(
"Report: {0} published successfully with no warnings", reportName);
                }

            }

            
catch (Exception e)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
{
                Console.WriteLine(e.Message);
            }

        }

 其中主要通过 rs.CreateDataSource 方法来创建数据源。rs.CreateReport 来创建报表,下面是完整项目,其中Test()方法包含使用例子。大家要注意的是其中添加了Web引用 ,“http://localhost/reportserver/reportservice2005.asmx?wsdl”,并将此Web 引用重命名为 ReportService2005。

 SSRSAPISample.rar

转载于:https://www.cnblogs.com/starsword_z/archive/2009/03/02/1401664.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值