Reporting Service自动安装程序,

博客指出Reporting Service部署不便,可通过程序部署。介绍了添加本地WebService引用,地址可设为动态,还说明了创建对象、设置权限、创建文件夹和共享数据源等部署步骤。

Reporting Service部署不是很方便,但可以通过程度来部署!

首先添加本地WebService的引用,
地址是: http://localhost/ReportServer/ReportService.asmx引用,可以把这个地址设置为动态方便以后修改。

创建对象:
private ReportingService rs = new ReportingService();
设置权限:
rs.Credentials = CredentialCache.DefaultCredentials;
创建文件夹:
rs.CreateFolder(tgParent, "/", null);
创建共享数据源:

None.gif DataSourceDefinition dsd  =   new  DataSourceDefinition();
None.gif            dsd.CredentialRetrieval 
=  CredentialRetrievalEnum.Store;
None.gif            dsd.ConnectString 
=   " data source= "   +  ServerIP  +   " ;initial catalog=RiskH2000 " ;
None.gif            dsd.Enabled 
=   true ;
None.gif            dsd.EnabledSpecified 
=   true ;
None.gif            dsd.Extension 
=   " SQL " ;
None.gif            dsd.ImpersonateUser 
=   false ;
None.gif            dsd.ImpersonateUserSpecified 
=   true ;
None.gif            dsd.Prompt 
=   null ;
None.gif            dsd.UserName 
=  SqlUserName;
None.gif            dsd.Password 
=  sqlPassword;
None.gif            dsd.WindowsCredentials 
=   false ;
None.gif            
try
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                rs.CreateDataSource(name, parent, 
false, dsd, null);
ExpandedBlockEnd.gif            }

None.gif            
catch  (Exception ex)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                WirteMsg(ex.Message);
ExpandedBlockEnd.gif            }

上传报表文件:
None.gif try
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                FileStream stream 
= File.OpenRead(filePath + ReportName + ".rdl");
InBlock.gif                definition 
= new byte[stream.Length];
InBlock.gif                stream.Read(definition, 
0, (int) stream.Length);
InBlock.gif                stream.Close();
ExpandedBlockEnd.gif            }

None.gif            
catch  (IOException ex)
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                WirteMsg(ex.Message);
ExpandedBlockEnd.gif            }

None.gif            warn 
=  rs.CreateReport(ReportName,  string .Format( @" /{0} " ,parent),  true , definition,  null );
None.gif
None.gif            
if  (warn  !=   null )
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                
foreach (Warning w in warn)
InBlock.gif                    WirteMsg(w.Message);
ExpandedBlockEnd.gif            }

None.gif            
else
ExpandedBlockStart.gifContractedBlock.gif            
dot.gif {
InBlock.gif                WirteMsg(
string.Format("{0} 创建成功!", ReportName));
ExpandedBlockEnd.gif            }

None.gif

全部代码文件如下:
None.gif using  System;
None.gif
using  System.Configuration;
None.gif
using  System.IO;
None.gif
using  System.Net;
None.gif
using  ReportServiceSetup.RS;
None.gif
None.gif
namespace  ReportServiceSetup
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Form1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    public class DoSetting
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
private byte[] definition = null;
InBlock.gif        
private ReportingService rs = new ReportingService();
InBlock.gif        
private string tgParent = "";
InBlock.gif        
private string jGParent = "";
InBlock.gif        
private string headtgParent = "";
InBlock.gif        
private string headJgparent = "";
InBlock.gif        
private string ServerIP = "";
InBlock.gif        
private string SqlUserName = "risk";
InBlock.gif        
private string sqlPassword = "risk";
InBlock.gif        
private string projctPath = @"D:\hg";
InBlock.gif        
private string filePath = @"D:\HG\BIN\Reports\";
InBlock.gif        
private Warning[] warn = null;
InBlock.gif        DataSourceDefinition fDefinition;
InBlock.gif
InBlock.gif        
public DoSetting()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// Windows 窗体设计器支持所必需的
InBlock.gif            
//
InBlock.gif
            tgParent = GetSetting("TgParentName");
InBlock.gif            headtgParent 
= GetSetting("HeadTgParentName");
InBlock.gif            headJgparent 
=GetSetting("HeadJgParentName");
InBlock.gif            jGParent 
= GetSetting("JgParentName");
InBlock.gif            ServerIP 
= GetSetting("ServiceIP");
InBlock.gif            SqlUserName 
= GetSetting("SqlUserName");
InBlock.gif            sqlPassword 
= GetSetting("SqlUserPass");
InBlock.gif            projctPath 
= GetSetting("ProjectPath");
InBlock.gif            filePath 
= GetSetting("FilePath");
InBlock.gif            
//
InBlock.gif            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
InBlock.gif            
//
ExpandedSubBlockEnd.gif
        }

InBlock.gif
InBlock.gif        
public string GetSetting(string Name)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return ConfigurationSettings.AppSettings[Name];
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void DoIt()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            rs.Credentials 
= CredentialCache.DefaultCredentials;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                rs.CreateFolder(tgParent, 
"/"null);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                rs.CreateFolder(jGParent, 
"/"null);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            CreateDataSource(
"RiskSqlServerSource"string.Format(@"/{0}", tgParent));
InBlock.gif            CreateDataSource2(
"RiskSource"string.Format(@"/{0}", tgParent));
InBlock.gif            CreateDataSource(
"ParamConn"string.Format(@"/{0}", jGParent));
InBlock.gif            CreateDataSource2(
"JGReport"string.Format(@"/{0}", jGParent));
InBlock.gif            publishTG();
InBlock.gif            PublicJG();
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public void DoIt2()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            rs.Credentials 
= CredentialCache.DefaultCredentials;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                rs.CreateFolder(headtgParent, 
"/"null);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                rs.CreateFolder(headJgparent, 
"/"null);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            CreateDataSource(
"RiskSqlServerSource"string.Format(@"/{0}", headtgParent));
InBlock.gif            CreateDataSource(
"ParamConn"string.Format(@"/{0}", headJgparent));
InBlock.gif            CreateDataSource2(
"JGReport"string.Format(@"/{0}", headJgparent));
InBlock.gif            publishHead();
InBlock.gif
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void publishHead()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            PublishReport(
"TG001",headtgParent);
InBlock.gif            PublishReport(
"TG001_2",headtgParent);
InBlock.gif            PublishReport(
"TG001_3",headtgParent);
InBlock.gif            PublishReport(
"JG001_3",headJgparent);
InBlock.gif            PublishReport(
"JG001_E",headJgparent);
InBlock.gif            PublishReport(
"JG001_I",headJgparent);
InBlock.gif            PublishReport(
"JG001_IE",headJgparent);
InBlock.gif            PublishReport(
"JG001_2",headJgparent);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
private void publishTG()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            PublishReport(
"TG001",tgParent);
InBlock.gif            PublishReport(
"TG001_2",tgParent);
InBlock.gif            PublishReport(
"TG001_3",tgParent);
InBlock.gif            PublishReport(
"Tg003",tgParent);
InBlock.gif            PublishReport(
"Tg004",tgParent);
InBlock.gif            PublishReport(
"TG005",tgParent);
InBlock.gif            PublishReport(
"TG006",tgParent);
InBlock.gif            PublishReport(
"TG006_2",tgParent);
InBlock.gif            PublishReport(
"TG008",tgParent);
InBlock.gif            PublishReport(
"TG009",tgParent);
InBlock.gif            PublishReport(
"TG009_2",tgParent);
InBlock.gif            PublishReport(
"TG009_3",tgParent);
InBlock.gif            PublishReport(
"TG014",tgParent);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public void PublicJG()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            PublishReport(
"JG023_2Report",jGParent);
InBlock.gif            PublishReport(
"JG001_3",jGParent);
InBlock.gif            PublishReport(
"JG001_E",jGParent);
InBlock.gif            PublishReport(
"JG001_I",jGParent);
InBlock.gif            PublishReport(
"JG001_IE",jGParent);
InBlock.gif            PublishReport(
"JG004",jGParent);
InBlock.gif            PublishReport(
"JG005",jGParent);
InBlock.gif            PublishReport(
"JG023_1Report",jGParent);
InBlock.gif            PublishReport(
"JG001_2",jGParent);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void CreateDataSource(string name, string parent)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            DataSourceDefinition dsd 
= new DataSourceDefinition();
InBlock.gif            dsd.CredentialRetrieval 
= CredentialRetrievalEnum.Store;
InBlock.gif            dsd.ConnectString 
= "data source=" + ServerIP + ";initial catalog=RiskH2000";
InBlock.gif            dsd.Enabled 
= true;
InBlock.gif            dsd.EnabledSpecified 
= true;
InBlock.gif            dsd.Extension 
= "SQL";
InBlock.gif            dsd.ImpersonateUser 
= false;
InBlock.gif            dsd.ImpersonateUserSpecified 
= true;
InBlock.gif            dsd.Prompt 
= null;
InBlock.gif            dsd.UserName 
= SqlUserName;
InBlock.gif            dsd.Password 
= sqlPassword;
InBlock.gif            dsd.WindowsCredentials 
= false;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                rs.CreateDataSource(name, parent, 
false, dsd, null);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void CreateDataSource2(string name, string parent)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif             fDefinition 
= new DataSourceDefinition();
InBlock.gif            fDefinition.CredentialRetrieval 
= CredentialRetrievalEnum.Integrated;
InBlock.gif            fDefinition.ConnectString 
= @"<Config><ReportPath>" + projctPath + @"Web\Bin\</ReportPath><XmlPath>" + projctPath + @"Xml\</XmlPath><ConnectionString>USER ID=" + SqlUserName + ";PASSWORD=" + sqlPassword + ";INITIAL CATALOG=RiskH2000; DATA SOURCE=" + ServerIP + ";CONNECT TIMEOUT=30</ConnectionString></Config>";
InBlock.gif            fDefinition.Enabled 
= true;
InBlock.gif            fDefinition.EnabledSpecified 
= true;
InBlock.gif            fDefinition.Extension 
= "YJC.Toolkit";
InBlock.gif            fDefinition.ImpersonateUser 
= false;
InBlock.gif            fDefinition.ImpersonateUserSpecified 
= true;
InBlock.gif            fDefinition.Prompt 
= null;
InBlock.gif            fDefinition.WindowsCredentials 
= true;
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                rs.CreateDataSource(name, parent, 
false, fDefinition, null);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (Exception ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(ex.Message);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void WirteMsg(string msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Console.WriteLine(msg);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public void PublishReport(string ReportName,string parent)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
try
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                FileStream stream 
= File.OpenRead(filePath + ReportName + ".rdl");
InBlock.gif                definition 
= new byte[stream.Length];
InBlock.gif                stream.Read(definition, 
0, (int) stream.Length);
InBlock.gif                stream.Close();
ExpandedSubBlockEnd.gif            }

InBlock.gif            
catch (IOException ex)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(ex.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            warn 
= rs.CreateReport(ReportName, string.Format(@"/{0}",parent), true, definition, null);
InBlock.gif
InBlock.gif            
if (warn != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
foreach (Warning w in warn)
InBlock.gif                    WirteMsg(w.Message);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                WirteMsg(
string.Format("{0} 创建成功!", ReportName));
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值