Problem with Initialization and Configuration of Report Server / Report Manager programatically via WMI
I am trying to handle the case that SQL Server 2005 Report Services is installed after SQL Server 2005 is installed which means that this is a file-only installation and the user doesn't have a chance to configure it during setup. The
normal answer is to use Report Service Configuration Tool to setup (i.e. Create Application Pool, Create Virtual Directory, Create Report Server Database..etc.). For the convinence of customers, I am trying to develop an application
which can automate exactly what Report Service COnfiguration does. So I researched on MSDN and found the Report Services WMI provider I need.
I am at the first step which I want to create a report server database on the target SQL server by invoking the GenerateDatabaseCreationScript method
The first problem I found is that method an undocumented parameter - Locale Id (Lcid). I tried to invokeMethod with or without the parameter, I am getting "Invalid Method Parameter(s)"
System.Management.ManagmentException, ErrorCode = InvalidMethodParameters
I google about this GenerateDatabaseCreationScript method and very little result is available and the only relevant one is a person having the same problem as mine.
Can anyone please help if they know how to solve it? Thanks a bunch.
Below is the code I used:
try
{
String WmiNamespace = String.Format(@"\\{0}\root\Microsoft\SqlServer\ReportServer\v9\Admin", serverName);
String WmiRSClass = String.Format(@"\\{0}\root\Microsoft\SqlServer\ReportServer\v9\admin:MSReportServer_ConfigurationSetting", serverName);
ManagementClass serverClass = new ManagementClass(WmiRSClass);
ManagementScope scope = new ManagementScope(WmiNamespace);
scope.Connect();
serverClass.Get();
if (serverClass != null)
{
//find out all methods for MSReportServer_ConfigurationSetting
foreach (MethodData md in serverClass.Methods)
{
Console.WriteLine("Method Name: ", md.Name.ToString());
if (md.Name == "GenerateDatabaseCreationScript")
{
foreach (PropertyData pd in md.OutParameters.Properties)
{
Console.WriteLine("Method Parameters Name: ", pd.Name.ToString());
}
}
}
//get the parameters for GenerateDatabaseCreationScript method
ManagementBaseObject inParams = serverClass.GetMethodParameters("GenerateDatabaseCreationScript");
//trace out the parameters name and type for GenerateDatabaseCreationScript
foreach (PropertyData property in inParams.Properties)
{
Console.WriteLine("Property Name: ", property.Name.ToString());
foreach (QualifierData qualifier in property.Qualifiers)
{
Console.WriteLine("Qualifier Name: ", qualifier.Name.ToString());
}
}
//assign [in] Parameters
inParams["DatabaseName"] = "ReportServer";
inParams["Lcid"] = 1033; //English - United States
//it will throw an exception here because of Invalid Method Parameter(s)
ManagementBaseObject outParams = serverClass.InvokeMethod("GenerateDatabaseCreationScript", inParams, null);
//trace out properties of Report Services. It is from MSDN sample codes
ManagementObjectCollection instances = serverClass.GetInstances();
foreach (ManagementObject instance in instances)
{
PropertyDataCollection instProps = instance.Properties;
Console.WriteLine("Property Name".PadRight(35) + "Value");
foreach (PropertyData propData in instProps)
{
Console.Out.Write(propData.Name.PadRight(35));
if (propData.Value == null)
{
Console.Out.WriteLine("<null>");
}
else
{
Console.Out.WriteLine(propData.Value.ToString());
returnValue = true;
}
}
}
}
Console.WriteLine("Press Enter to Conintune");
Console.ReadLine();
}
catch (Exception ex)
{
}
I am trying to handle the case that SQL Server 2005 Report Services is installed after SQL Server 2005 is installed which means that this is a file-only installation and the user doesn't have a chance to configure it during setup. The
normal answer is to use Report Service Configuration Tool to setup (i.e. Create Application Pool, Create Virtual Directory, Create Report Server Database..etc.). For the convinence of customers, I am trying to develop an application
which can automate exactly what Report Service COnfiguration does. So I researched on MSDN and found the Report Services WMI provider I need.
I am at the first step which I want to create a report server database on the target SQL server by invoking the GenerateDatabaseCreationScript method
The first problem I found is that method an undocumented parameter - Locale Id (Lcid). I tried to invokeMethod with or without the parameter, I am getting "Invalid Method Parameter(s)"
System.Management.ManagmentException, ErrorCode = InvalidMethodParameters
I google about this GenerateDatabaseCreationScript method and very little result is available and the only relevant one is a person having the same problem as mine.
Can anyone please help if they know how to solve it? Thanks a bunch.
Below is the code I used:
try
{
String WmiNamespace = String.Format(@"\\{0}\root\Microsoft\SqlServer\ReportServer\v9\Admin", serverName);
String WmiRSClass = String.Format(@"\\{0}\root\Microsoft\SqlServer\ReportServer\v9\admin:MSReportServer_ConfigurationSetting", serverName);
ManagementClass serverClass = new ManagementClass(WmiRSClass);
ManagementScope scope = new ManagementScope(WmiNamespace);
scope.Connect();
serverClass.Get();
if (serverClass != null)
{
//find out all methods for MSReportServer_ConfigurationSetting
foreach (MethodData md in serverClass.Methods)
{
Console.WriteLine("Method Name: ", md.Name.ToString());
if (md.Name == "GenerateDatabaseCreationScript")
{
foreach (PropertyData pd in md.OutParameters.Properties)
{
Console.WriteLine("Method Parameters Name: ", pd.Name.ToString());
}
}
}
//get the parameters for GenerateDatabaseCreationScript method
ManagementBaseObject inParams = serverClass.GetMethodParameters("GenerateDatabaseCreationScript");
//trace out the parameters name and type for GenerateDatabaseCreationScript
foreach (PropertyData property in inParams.Properties)
{
Console.WriteLine("Property Name: ", property.Name.ToString());
foreach (QualifierData qualifier in property.Qualifiers)
{
Console.WriteLine("Qualifier Name: ", qualifier.Name.ToString());
}
}
//assign [in] Parameters
inParams["DatabaseName"] = "ReportServer";
inParams["Lcid"] = 1033; //English - United States
//it will throw an exception here because of Invalid Method Parameter(s)
ManagementBaseObject outParams = serverClass.InvokeMethod("GenerateDatabaseCreationScript", inParams, null);
//trace out properties of Report Services. It is from MSDN sample codes
ManagementObjectCollection instances = serverClass.GetInstances();
foreach (ManagementObject instance in instances)
{
PropertyDataCollection instProps = instance.Properties;
Console.WriteLine("Property Name".PadRight(35) + "Value");
foreach (PropertyData propData in instProps)
{
Console.Out.Write(propData.Name.PadRight(35));
if (propData.Value == null)
{
Console.Out.WriteLine("<null>");
}
else
{
Console.Out.WriteLine(propData.Value.ToString());
returnValue = true;
}
}
}
}
Console.WriteLine("Press Enter to Conintune");
Console.ReadLine();
}
catch (Exception ex)
{
}