Schedule SSIS Package using C# - c#

What I want to do, is to schedule a SSIS package, using C#. the missing part is, how to tell the agent that this schedulare is for the SSIS package "X", Here is my code :
Server srv = new Server();
//Define an Operator object variable by supplying the Agent (parent JobServer object) and the name in the constructor.
Operator op = new Operator(srv.JobServer, "AC_Operator") { NetSendAddress = "Network1_PC" };
//Create the operator on the instance of SQL Server Agent.
op.Create();
//Define a Job object variable by supplying the Agent and the name arguments in the constructor and setting properties.
Job jb = new Job(srv.JobServer, "AC_Job");
//Specify which operator to inform and the completion action.
jb.OperatorToNetSend = "AC_Operator";
jb.NetSendLevel = CompletionAction.Always;
//Create the job on the instance of SQL Server Agent.
jb.Create();
//Define a JobStep object variable by supplying the parent job and name arguments in the constructor.
JobStep jbstp = new JobStep(jb, "AC_Job_Step");
jbstp.OnSuccessAction = StepCompletionAction.QuitWithSuccess;
jbstp.OnFailAction = StepCompletionAction.QuitWithFailure;
//Create the job step on the instance of SQL Agent.
jbstp.Create();
//Define a JobSchedule object variable by supplying the parent job and name arguments in the constructor.
JobSchedule jbsch = new JobSchedule(jb, "AC_Job_Schedule");
//Set properties to define the schedule frequency, and duration.
jbsch.FrequencyTypes = FrequencyTypes.Daily;
jbsch.FrequencySubDayTypes = FrequencySubDayTypes.Minute;
jbsch.FrequencySubDayInterval = 30;
TimeSpan ts1 = new TimeSpan(9, 0, 0);
jbsch.ActiveStartTimeOfDay = ts1;
TimeSpan ts2 = new TimeSpan(17, 0, 0);
jbsch.ActiveEndTimeOfDay = ts2;
jbsch.FrequencyInterval = 1;
DateTime d = new DateTime(2003, 1, 1);
jbsch.ActiveStartDate = d;
//Create the job schedule on the instance of SQL Agent.
jbsch.Create();
Thanks for your time.

What you are needing to do is set the jobstep's SubSystem and then build your Command. In comparing the .NET generated code to a SQL Agent created job, the only difference I noticed was the assignment of the DatabaseName property so I set that as well.
You'll also undoubtedly want to look at dtexec to figure out how to configure and invoke your package or you can cheat like I do and use dtexecui or the Agent to build out the SET and other commands and then paste those in as the source command.
//Define a JobStep object variable by supplying the parent job and name arguments in the constructor.
JobStep jbstp = new JobStep(jb, "AC_Job_Step");
jbstp.OnSuccessAction = StepCompletionAction.QuitWithSuccess;
jbstp.OnFailAction = StepCompletionAction.QuitWithFailure;
string command = string.Empty;
command = #"/FILE ""C:\sandbox\SSISHackAndSlash2008\SSISHackAndSlash2008\EzAPI_Recipe01.dtsx"" /CHECKPOINTING OFF /REPORTING E";
jbstp.SubSystem = AgentSubSystem.Ssis;
jbstp.DatabaseName = "master";
jbstp.Command = command;
//Create the job step on the instance of SQL Agent.
jbstp.Create();

Related

How do I assign values to my nodes instantiates in my OPC UA server (C # code)

I am a beginner in OPC UA server and using C # to develop the server. I have used UA Modeller to create my objects and include it in the server while using C #.
I have instantiated the objects into my server and now I want to assign values to these nodes ? How do I do that? and how can I make these assigned values constantly change as if it is attached to a real time data source ?
Console.WriteLine("Loading the MyIM Model.");
ImportUaNodeset(Assembly.GetEntryAssembly(), "myinformationmodel_1.1.0.xml");
Console.WriteLine("myIM sucessfully loaded");
CreateObjectSettings settings = new CreateObjectSettings()
{
ParentNodeId = UnifiedAutomation.UaBase.ObjectIds.ObjectsFolder,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("myIM", DefaultNamespaceIndex),
BrowseName = new QualifiedName("Controllers", DefaultNamespaceIndex),
TypeDefinitionId = UnifiedAutomation.UaBase.ObjectTypeIds.FolderType
};
ObjectNode controllersNode = CreateObject(Server.DefaultRequestContext, settings);
settings = new CreateObjectSettings()
{
ParentNodeId = controllersNode.NodeId,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("Bodyshop", DefaultNamespaceIndex),
BrowseName = new QualifiedName("Bodyshop", DefaultNamespaceIndex),
TypeDefinitionId = new NodeId(myAG.myIM.ObjectTypes.BodyshopProductionEquipmentType, DefaultNamespaceIndex)
};
CreateObject(Server.DefaultRequestContext, settings);
settings = new CreateObjectSettings()
{
ParentNodeId = controllersNode.NodeId,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("PaintShop", DefaultNamespaceIndex),
BrowseName = new QualifiedName("PaintShop", DefaultNamespaceIndex),
TypeDefinitionId = new NodeId(myAG.myIM.ObjectTypes.PaintshopProductionEquipmentType, DefaultNamespaceIndex)
};
CreateObject(Server.DefaultRequestContext, settings);
settings = new CreateObjectSettings()
{
ParentNodeId = controllersNode.NodeId,
ReferenceTypeId = UnifiedAutomation.UaBase.ReferenceTypeIds.Organizes,
RequestedNodeId = new NodeId("ProductionMainFolder", DefaultNamespaceIndex),
BrowseName = new QualifiedName("ProductionMainFolder", DefaultNamespaceIndex),
TypeDefinitionId = new NodeId(myAG.myIM.ObjectTypes.ProductionEquipmentType, DefaultNamespaceIndex)
};
CreateObject(Server.DefaultRequestContext, settings);
Not sure which OPC UA C# library you are using but I can explain it in general
The CreateObject method usually return a state object. In case of OPC Foundation C# library the state object is of type BaseDataVariableState and has the property called Value of type object. Which you could set at anytime.
While updating the value you should also update the Timestamp property (best set to DateTime.UtcNow) and clear the change mask (call method ClearChangeMasks).
To simulate a data source, you typically start a timer (e.g. after the end of CreateAddressSpace method), and everytime the timer is elapsed you update value and timestamp of your variables instances.
The OPC foundation library provides a class called Opc.Ua.Test.DataGenerator that generates random values for you and is aware of the OPC UA base types.
Some inspiration if you need something different then random values, like dips, spikes, trends you can have a look into the plugins folder of iot-edge-opc-plc which is an OPC UA server simulation.
If you are looking for a way to to use your own OPC UA classes as C# classes you could start with the DataTypes example from OPC Foundation.

QlikView Management API erroring when including distribute

Hi I have created a task using the QMS API and have had success populating all general, reload, and reduce tabs but I am now having trouble when working with the distribute category. I'm trying to "Distribute to QlikView Server " and add a view users to distribute to. Except whenever I include distribute in the DocumentTaskScope (DocumentTaskScope.Distribute), the task seems to lose reference to the SourceDocument and the reduce category gets wiped, along with options from general and reload being lost. This is indicated by this dialog appearing when I click manage users when on the distribute tab.
Also here is what my distribute panel actually looks like, as you can see it is missing the "Distribute to QlikView Server" area that should normally be there:
Here is my code for the distribute section, I am writing this program in c# and the program builds and executes with no errors, it just doesn't produce the intended result.
I was thinking if it had something to do with the server name syntax or if the ID member. The documentation indicated that this is meant to be the "The ID of the QlikView Server. ", so I used the id of the qlikview service but I am not certain this is what it is looking for.
//Distribute static ("Manually" in QV Management Console)
DocumentTask.TaskDistribute.TaskDistributeStatic tds = new DocumentTask.TaskDistribute.TaskDistributeStatic();
TaskDistributionDestination.TaskDistributionDestinationQlikViewServer tddqvs = new TaskDistributionDestination.TaskDistributionDestinationQlikViewServer();
tddqvs.Name = "QVS#qlikviewdev";
tddqvs.Mount = "Root Folder";
tddqvs.ID = qvsGuid;
TaskDistributionEntry newEntry = new TaskDistributionEntry();
newEntry.Destination = new TaskDistributionDestination();
TaskDistributionDestination tdd = new TaskDistributionDestination();
TaskDistributionDestinationType tddt = new TaskDistributionDestinationType();
tddt = TaskDistributionDestinationType.QlikViewServer;
newEntry.Destination.Type = tddt;
newEntry.Destination.QlikViewServer = tddqvs;
TaskDistributionDestination.TaskDistributionDestinationFolder tddf = new TaskDistributionDestination.TaskDistributionDestinationFolder();
tddf.Name = "N/A";
newEntry.Destination.Folder = tddf;
DirectoryServiceObject[] serviceObject = new DirectoryServiceObject[2];
DirectoryServiceObject dso1 = new DirectoryServiceObject();
DirectoryServiceObject dso2 = new DirectoryServiceObject();
dso1.Name = "QlikView_Admin";
dso1.Type = DirectoryServiceObjectType.Named;
dso1.OtherProperty = "N/A";
dso2.Name = "Qlikview_PowerUser";
dso2.Type = DirectoryServiceObjectType.Named;
dso2.OtherProperty = "N/A";
serviceObject[0] = dso1;
serviceObject[1] = dso2;
newEntry.Recipients = serviceObject;
TaskDistributionEntry[] tdeArray = new TaskDistributionEntry[1];
tdeArray[0] = newEntry;
tds.DistributionEntries = tdeArray;
docTask.Distribute = new DocumentTask.TaskDistribute();
docTask.Distribute.Static = tds;
DocumentTask.TaskDistribute.TaskDistributeDynamic taskDistributeDynamic = new DocumentTask.TaskDistribute.TaskDistributeDynamic();
taskDistributeDynamic.Destinations = new List<TaskDistributionDestination>().ToArray();
taskDistributeDynamic.FieldName = string.Empty;
taskDistributeDynamic.IdentityType = UserIdentityValueType.DisplayName;
docTask.Distribute.Dynamic = taskDistributeDynamic;
DocumentTask.TaskDistribute.TaskDistributeNotification tdn = new DocumentTask.TaskDistribute.TaskDistributeNotification();
tdn.SendNotificationEmail = false;
docTask.Distribute.Notification = tdn;
DocumentTask.TaskDistribute.TaskDistributeOutput tdo = new DocumentTask.TaskDistribute.TaskDistributeOutput();
tdo.Type = TaskDistributionOutputType.QlikViewDocument;
docTask.Distribute.Output = tdo;
Turns out I was using the wrong GUID for the TaskDistributionDestinationQlikViewServer Objects' ID field. Once I set it to be the ID of the QVS#(servername) service, it worked.

How to trigger a SSRS Subscription based on an event?

Is there a way by which I can trigger a SSRS subscription (Time based) whenever there is an event like file created in a shared folder? Can we do it with powershell or C#?
Is there a out of box feature available in SSRS (though I don't think there is any)?
I am using SQL Server 2008 R2.
Yes, we do something like this here. You can use the FireSubscription function of the Reporting Services web services to trigger a subscription. Here's a detailed explanation of how to set it up:
Firing a Reporting Services Subscription
You can use the FileSystemWatcher to tell when your file is dropped and then fire the subscription off. It's asynchronous though so you don't get notification if the report was sent successfully... only that it was successfully queued up. Also you first modify the parameters of the subscription before you fire it, so you have to make sure that you don't have more than one program to trigger the subscription or it might end up tripping over itself.
Another slightly more complicated way to do it is to use the Render function to generate a report and then have your program manage the emailing.
Render Function
This way you don't have to create a dummy subscription and you'll know immediately if it was sent successfully with the correct parameters.
One final note... if you have the Enterprise Edition (which you probably don't), it comes with Data Driven Report Subscriptions, which you could use to trigger a subscription:
Creating a Data-Driven Subscription
Here i have used timely subscription , i had requirement to generate report
on some button click, so i created subscription which will fire after one minute and generate PDF report.
And I got all help from this article :
http://odetocode.com/articles/114.aspx
You need to add webservice reference of webservice provided by SSRS
http://mymachine/ReportServer/ReportService2010.asmx
Here #"\MyMachineName\Share", is path where my pdf was stored
(PATH:The folder path or UNC file share path to which to save the report.
https://msdn.microsoft.com/en-us/library/ms154020.aspx)
So you can call generate subscription as per your need on file created.
using Test_WebProject.ReportService2010;
private static ExtensionSettings GetExtensionSettings()
{
ParameterValue[] extensionParams = new ParameterValue[7];
for (int i = 0; i < extensionParams.Length; i++)
extensionParams[i] = new ParameterValue();
extensionParams[0].Name = "FILENAME";
extensionParams[0].Value = "Test1#TimeStamp";
extensionParams[1].Name = "FILEEXTN";
extensionParams[1].Value = "true";
extensionParams[2].Name = "PATH";
extensionParams[2].Value = #"\\MyMachineName\Share";
extensionParams[3].Name = "RENDER_FORMAT";
extensionParams[3].Value = "PDF";
extensionParams[4].Name = "WRITEMODE";
extensionParams[4].Value = "None"; //"Overwrite ";// "AutoIncrement";
extensionParams[5].Name = "USERNAME";
extensionParams[5].Value = "gmd";
extensionParams[6].Name = "PASSWORD";
extensionParams[6].Value = "password123";
ExtensionSettings extensionSettings = new ExtensionSettings();
extensionSettings.Extension = "Report Server FileShare"; // EXTENSION_FILESHARE;
extensionSettings.ParameterValues = extensionParams;
return extensionSettings;
}
static void generateSubscription()
{
string report = #"/MyReports/TestSSRSSubscrptionReport";
string description = "My Test subscription2010";
string eventType = "TimedSubscription";
ExtensionSettings extSettings = GetExtensionSettings();
List<ReportService2010.ParameterValue> parameters = new List<ReportService2010.ParameterValue>();
parameters.Add(new ReportService2010.ParameterValue() { Name = "EmployeeKey", Value = "9" });
parameters.Add(new ReportService2010.ParameterValue() { Name = "SelectedColumn", Value = "EmployeeKey" });
parameters.Add(new ReportService2010.ParameterValue() { Name = "ParamSelectedColumns", Value = "FirstName" });
parameters.Add(new ReportService2010.ParameterValue() { Name = "ParamSelectedColumns", Value = "LastName" });
NetworkCredential credentials = new NetworkCredential("gmd", "password123");
ReportService2010.ReportingService2010 rs = new ReportService2010.ReportingService2010();
rs.Credentials = credentials; // System.Net.CredentialCache.DefaultCredentials;
DateTime topDatetime = DateTime.Now;
topDatetime = topDatetime.AddMinutes(1);
string scheduleXml = "<ScheduleDefinition><StartDateTime>";
scheduleXml += topDatetime.ToShortDateString() + " " + topDatetime.ToShortTimeString();
scheduleXml += "</StartDateTime></ScheduleDefinition>";
string sid = rs.CreateSubscription(report, extSettings, description, eventType, scheduleXml, parameters.ToArray());
}
You could create a windows service that uses FileSystemWatcher (https://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher%28v=vs.110%29.aspx) and then just trigger your job on the changed event.

set sql agent job schedule time in C#

I want to schedule a group of queries run weekly/configurable.I found below code by googling but am trying to set sheduler timings for weekly execution now.Also i want it to be configurable. Am pretty new to this so somw help would be appreciated!
Server server = new Server(".");
// Get instance of SQL Agent SMO object
JobServer jobServer = server.JobServer;
Job job = null;
JobStep step = null;
JobSchedule schedule = null;
// Create a schedule
schedule = new JobSchedule(jobServer, "Schedule_1");
schedule.FrequencyTypes = FrequencyTypes.OneTime;
schedule.ActiveStartDate = DateTime.Today;
//schedule.ActiveStartTimeOfDay = new TimeSpan(DateTime.Now.Hour, (DateTime.Now.Minute + 2), 0);
schedule.Create();
// Create Job
job = new Job(jobServer, "Job_1");
job.Create();
job.AddSharedSchedule(schedule.ID);
job.ApplyToTargetServer(server.Name);
job.
// Create JobStep
step = new JobStep(job, "Step_1");
step.Command = "SELECT 1";
step.SubSystem = AgentSubSystem.TransactSql;
step.Create();
Provide links to the job scheduler examples.Am lost in finding how to set schedule timings!
The FrequencyTypes Enum that you are using in the code should have a Weekly value.
http://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.frequencytypes.aspx

how to pass arguments in EMR job to use in bootstrap script

I have a bootstrap script which runs with my EMR job.
I need to pass a parameter to this script so I can configure a path for different environments
The following line in my script needs to use it
path=OVA/{EnvironmentName}/Scripts/UniqueUsers
I am using C# to invoke a streaming EMR job. how do I pass this argument while I create the job?
HadoopJarStepConfig config = new StreamingStep()
.WithInputs(input)
.WithOutput(output)
.WithMapper(configMapperLocation)
.WithReducer(configReducerLocation)
.ToHadoopJarStepConfig();
string configName = string.Format("Unique_Users_config_{0}", outputFolder);
StepConfig uniqueUsersDaily = new StepConfig()
.WithName(configName)
.WithActionOnFailure("TERMINATE_JOB_FLOW")
.WithHadoopJarStep(config);
ScriptBootstrapActionConfig bootstrapActionScript = new ScriptBootstrapActionConfig()
.WithPath(configBootStrapScriptLocation);
BootstrapActionConfig bootstrapAction = new BootstrapActionConfig()
.WithName("CustomAction")
.WithScriptBootstrapAction(bootstrapActionScript);
string jobName = string.Format("Unique_User_DailyJob_{0}", outputFolder);
RunJobFlowRequest jobRequest = new RunJobFlowRequest()
.WithName(jobName)
.WithBootstrapActions(bootstrapAction)
.WithSteps(uniqueUsersDaily)
.WithLogUri(configHadoopLogLocation)
.WithInstances(new JobFlowInstancesConfig()
.WithHadoopVersion(configHadoopVersion)
.WithInstanceCount(2)
.WithKeepJobFlowAliveWhenNoSteps(false)
.WithMasterInstanceType(configMasterInstanceType)
.WithSlaveInstanceType(configSlaveInstanceType));
You can use withArgs() of ScriptBootstrapActionConfig, in Java you can do as follows, I am sure there is a similar method for C#:
ScriptBootstrapActionConfig bootstrapActionScript = new ScriptBootstrapActionConfig()
.WithPath(configBootStrapScriptLocation)
.WithArgs(List<String> args);

Categories

Resources