Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem configuring Report Server via Report Services WMI

Status
Not open for further replies.

fongph

Programmer
Jan 12, 2008
1
0
0
US
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)
{

}
 
If I was going to do this I would use SSRS's utilities and batch probably. Between the RSConfig and RSKeyMgmt you should be able to fully configure the instance of RS without a problem after the install. Depending on the installation methods you're using you can directly call the batch or even just a script in order depending in the installation process

I'll try to get some time to setup an example and maybe an unattended install. I'll psot it if I do (no promises...long weekend ;-))

[sub]____________ signature below ______________
Backups are for sissies!!!!
coming to your keyboards soon[/sub]
 
You are creating a new Management Object rather than connecting to the one you want to use in your system. See below

ManagementClass serverClass;
ManagementScope scope;
scope = new ManagementScope(WmiNamespace);
scope.Connect();
serverClass = new ManagementClass(WmiRSClass);
serverClass.Scope = scope;
ManagementObjectCollection mcol = serverClass.GetInstances();
ManagementObject instance = null;

foreach (ManagementObject strt in mcol)
{
// I have hard coded my SQL instance here
if (Convert.ToString(strt["InstanceName"]) == "SQLSERVER2005")
{
instance = strt;
}
}

if (instance != null)
{
ManagementBaseObject inParams = instance.GetMethodParameters("GenerateDatabaseCreationScript");
inParams["DatabaseName"] = Name;
inParams["Lcid"] = "1033";

ManagementBaseObject outParams = instance.InvokeMethod("GenerateDatabaseCreationScript", inParams,null);

object s = outParams["Script"];
// s will contain the script
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top