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
Related
Im trying to get a VendorPayment object internal id by having its external id.
Maybe someone did such a search? the API seems to be very verbose..
help would be appreciated.
If you have the externalId, you don’t need to do a search. You can use the get operation by creating a RecordRef that references the externalId.
Making tests about this i get this code, i give to you this example(in PHP) of searching items by internal id maybe helps someone.
$item_id = new RecordRef();
$item_id->internalId = $by_item;
$rec = new SearchMultiSelectField();
$rec->operator = SearchMultiSelectFieldOperator::anyOf;
$rec->searchValue = $item_id;
$itemSearchBasic->internalId = $rec;
$itemSearchBasic = new ItemSearchBasic();
$itemSearchBasic->type = $itemTypeFld;
$itemSearch = new ItemSearch();
$itemSearch->basic = $condition;
$search_field = new ItemSearchAdvanced();
$search_field->criteria = $itemSearch;
$request = new SearchRequest();
$request->searchRecord = $search_field;
And then you use your Netsuite Client to execute the search.
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.
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.
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();
I created a program a while ago using C# that does some automation for a completely different program, but found that I need to access data from a Lotus Notes database. The only problem is, I can only seem to figure out how to open the database by the server's name (using session.GetDatabase())... I can't figure out how to open it by Replica ID. Does anyone know how I would go about that? (I don't want my program going down every time the server changes.)
public static string[] GetLotusNotesHelpTickets()
{
NotesSession session = new NotesSession();
session.Initialize(Password);
// 85256B45:000EE057 = NTNOTES1A Server Replica ID
NotesDatabase database = session.GetDatabase("NTNOTES1A", "is/gs/gshd.nsf", false);
string SearchFormula = string.Concat("Form = \"Call Ticket\""
, " & GroupAssignedTo = \"Business Systems\""
, " & CallStatus = \"Open\"");
NotesDocumentCollection collection = database.Search(SearchFormula, null, 0);
NotesDocument document = collection.GetFirstDocument();
string[] ticketList = new string[collection.Count];
for (int i = 0; i < collection.Count; ++i)
{
ticketList[i] = ((object[])(document.GetItemValue("TicketNumber")))[0].ToString();
document = collection.GetNextDocument(document);
}
document = null;
collection = null;
database = null;
session = null;
return ticketList;
}
This code is working fine, but if the server changed from NTNOTES1A, then nothing is going to work anymore.
you'll need to use the notesDbDirectory.OpenDatabaseByReplicaID(rid$) method. To get the NotesDbDirectory, you can use the getDbDirectory method of the session
Set notesDbDirectory = notesSession.GetDbDirectory( serverName$ )
So you can use the code below to get a database by replicaID.
public static string[] GetLotusNotesHelpTickets()
{
NotesSession session = new NotesSession();
session.Initialize(Password);
Set notesDBDirectory = session.GetDbDirectory("NTNOTES1A")
// 85256B45:000EE057 = NTNOTES1A Server Replica ID
NotesDatabase database = notesDBDirectory.OpenDatabaseByReplicaID("85256B45:000EE057")
string SearchFormula = string.Concat("Form = \"Call Ticket\""
, " & GroupAssignedTo = \"Business Systems\""
, " & CallStatus = \"Open\"");
NotesDocumentCollection collection = database.Search(SearchFormula, null, 0);
NotesDocument document = collection.GetFirstDocument();
string[] ticketList = new string[collection.Count];
for (int i = 0; i < collection.Count; ++i)
{
ticketList[i] = ((object[])(document.GetItemValue("TicketNumber")))[0].ToString();
document = collection.GetNextDocument(document);
}
document = null;
collection = null;
database = null;
session = null;
return ticketList;
}
Unfortunately, this only solves half of your problem. I know you'd rather just tell Notes to fetch the database with a particular replicaID from the server closest to the client, just like the Notes Client does when you click on a DBLink or Bookmark. However, there is (or appears to be) no way to do that using the Notes APIs.
My suggestion is to either loop through a hard-coded list of potential servers by name, and check to see if the database is found (the OpenDatabaseByReplicaID method returns ERR_SYS_FILE_NOT_FOUND (error 0FA3) if the database is not found). If that's not a good option, perhaps you can easily expose the servername in an admin menu of your app so it can be changed easily if the server name changes at some point.
set database = new NotesDatabase("")
call database.OpenByReplicaID("repid")