SSIS- SQL AGENT Sending Mail for Each hour - ssis

i have designed a SSIS Package which will load some data to table
from the file available in a folder.
once data got loaded file move to archieve.
Client requested to have mail trigger at the end of process, so i implement
it through send mail task.
The pooling mechanism was done via agent job which run after evry 1 hour
to check existence of file.
The problem starts here.
it start sending mail every 1 hr to user
will it be possible to do some modification.
Thanks You All...... i think my question was not clear. The Problem i am facing is my package is start trigger mail every 1 hour, even when there is no file in source folder. i want to trigger mail when there is a file in Source folder, and after processing the file mail should get triggered, so user can come to know that file which they placed in the folder is got processed. But in present scenario, because i used agent job, which is checking for the file every 1 hour, even if file is not there mail is getting triggered to user. Please help me on this.
Can any one please suggest how can i rectify it.
Thanks

Yes, there are numerous ways to handle this depending on what you want to do.
They all involve only sending the email if some condition is true. You will have to decide what that condition is, and then that will suggest the best way to handle it.
You can set a variable and use an expression in the precedence constraint to only go to the Send Mail Task if the variable is true, for example.
If you want to look at a more complicated set of conditions, you can use a script task.

I would have sent mail only if the package fails. Not sure, your purpose of sending mail to the Client.
If the issue is sending mail every 1 hour is too much for the client.
Send mail if package fails and keep the status of every hour in a file (Using Script task, use variable to get the current Hour and write the Hour and Status to file) and send a consolidated mail at the end like.
Date: 09/23/2016
Hr - STATUS
-------------
00 - SUCCESS
01 - FAILED
.
.
.
23 - SUCCESS
If you want to send the consolidated mail at particular time, use the Variable used in precedence constraint before the send mail task.
Edit:
As per your update on clarification. Create a boolean variable to get the existence of the file using script task. Use that variable in precedence constraint before the Send Mail task.
http://sql-articles.com/articles/bi/file-exists-check-in-ssis/
Also, Refer

Related

is there any way to create an excel file and save it or email it?

is there any way using SSIS (or any MSSQL Server features) to automatically run a stored procedure and have the output saved as an Excel files (or even flat file) and then have the newly created file sent to people via email?
sorry im a complete newbie to SSIS.
In broad strokes, you'll have an SSIS package with 2 tasks and 3 connection manager.
The first task is a Data Flow Task. Much as the name implies, the data is going to flow here - in your case, from SQL Server to Excel.
In the Data Flow task, add an OLE DB Source to the data flow. It will ask what Connection Manager to use and you'll create a new one pointed at your source system. Change the source from the Table Selector to a Query and then reference your stored procedure EXECUTE dbo.ExportDaily'
Hopefully, the procedure is nothing more than select col1, col2, colN from table where colDate = cast(getdate() as date) Otherwise, you might run into challenges for the component to determine the source metadata. Metadata is the name of the game in an SSIS data flow. If you have trouble, the resolution is version dependent - pre 2012 you'd have a null operation select as your starting point. 2012+ you use the WITH RESULT_SETS to describe the output shape.
With our source settled, we need to land that data somewhere and you've indicated Excel. Drag an Excel destination onto the canvas and again, this is going to need a connection manager so let it create one after you define where the data should land. Where you land the data is important. On your machine, C:\user\pmaj\Documents is a valid path, but when this runs on a server as ServerUser1... Not so much. I have a pattern of C:\ssisdata\SubjectArea\Input & Output & Archive folders.
Click into the Columns tab, and there's nothing to do here as it auto-mapped source columns to the destination. Sort the target column names by clicking on the header. A good practice is to scroll through the listing and look for anything that is unmapped.
Run the package and confirm that we have a new file generated and it has data. Close Excel and run it again. It should have clobbered the file we made. If it errors (and you don't have your "finger" on the file by having it open in Excel, then you need to find the setting in the Excel destination that says overwrite existing file)
You've now solved the exporting data to Excel task. Now you want to share your newfound wisdom with someone else and you want to use email to do so.
There are two ways of sending email. The most common will be the Email task. You'll need to establish a connection to your SMTP server and I find this tends to be more difficult in the cloud based world - especially with authentication and this thing running as an unattended job.
At this point, I'm assuming you've got a valid SMTP connection manager established. The Send Email Task is straightfoward. Define who is receiving the email, the subject, body and then add your attachment.
An alternative to the Send Mail Task, is to use an Execute SQL Task. The DBAs likely already have sp_send_dbmail configured on your server as they want the server to alert them when bad things happen. Sending your files through that process is easier as someone else has already solved the hard problems of smtp connections, permissions, etc.
EXECUTE msdb.dbo.sp_send_dbmail
#profile_name = 'TheDbasToldMeWhatThisIs'
, #recipients ='pmaj#a.com;billinkc#b.com'
, #subject = 'Daily excel'
, #body = 'Read this and do something'
, #file_attachments = 'C:\ssisdata\daily\daily.xlsx';
Besides using existing and maintained mechanism for mailing the files, Execute SQL Task is easily parameterized with the ? place holder so if you need to change profile as the package is deployed through dev/uat/prod, you can create SSIS Variables and Parameters and map values into the procedure's parameters and configure those values post deployment.

SSIS event handler script task

i have a package that has several event handlers that execute a script task on failure when the package fails.. Problem is its generating a email that i have NO IDEA how.. When the package fails it executes a stored procedure that grabs the email distribution list from a SQL table and sends an email. However one email is being sent out to ppl who are not with the company and ive been told twice to change the DL list.. I checked the SQL table and the people that are getting the email are not listed any where in the distribution list.. Is there any way to search anywhere in the package to find out how the email is being generated. Ive spent hours and hours going through the scrip tasks and the code is no where to be found
You can use the package explorer (to the right of the event handler tab) to navigate through the entire package and look at the event handlers for every executable. It's possible that there are multiple event handlers, one at the package level and maybe one defined on a particular task, which is hardcoded with email addresses.
You can also, right click on the package in the solution explorer and select View Code. This will open the package in xml, which you can then use ctrl+F to find a certain string.
Advice Section
While you didn't ask for it, please let me add a few words of guidance. Event handlers are evil for this very reason. They are a hidden GOTO that you are lucky to notice at all, even if you've developed the package in the first place.
If event handling is required, use the precedence constraints in the control flow. Throw everything in a container, connect it to the script task and define the constraint to trigger on failure.
To go one step further, keep your emails out of your ssis packages. Use SQL agent or whatever scheduler you are using to post messages about failures.

SSIS Mail Triggered wrongly

i have a SSIS Package which schedule to check in every 10 min for the file,
and Once the file placed in the path, it execute and triggered mail.
The issue is even when file not placed it start sending mail in every 10 min.
How to handle it.
You should handle this by correcting the code that checks for the file and sends the mail.

Automator Sending Email With Incomplete Table Before MySQL Query Finishes

I don't know if this is in need of a MySQL fix or an Automator fix, but I have a query that generally takes around five minutes to run and save to my tmp folder -- which a simplified version looks like this:
SELECT * FROM table
INTO OUTFILE '/tmp/test.txt';
From there, I have an Automator script Folder Action that grabs whatever file hits the 'tmp' folder, attaches it to an email, and sends it to the email address I designate. This works when the SQL query runs in a second or so, but it basically sends a blank .txt when the query takes a bit to run because it's sending it as soon as the file is created in the folder.
Is there any way to either stop SQL from creating the table in the folder until the query is completed? Or a way to tell Automator to not send the email until it's fully downloaded? I know I can use a delay function in Automator but I'd rather figure out something that can handle different query lengths if possible.
Please let me know if I can provide any other information that's helpful. Thanks!
At this point, it seems like you just need to know how long the query's going to take to run and then build a delay into Automator/AppleScript before it starts running.

CRM Plug-In Call retrieves a subset of Invoice Lines when creating an Invoice from an order

We are developing a CRM plug-in that would be triggered whenever an Invoice is Generated in CRM from an Order.
The typical action would be going to a Sales Order and clicking on “Create an Invoice”.
The end game of the plug-in is to integrate the Invoice into a Remote system along with the header and lines.
Plug-in works in the following way:
Plugin is registered with the CRM Invoice for the “Create” Event.
Plugin runs “Asynchronously” via a Post operation of the Invoice Header.
Upon hitting “Create Invoice”, UI Action; Plugin sends the newly created Invoice GUID to a service, this is typically a POST operation:
a. We Basically make a call to an ASPX page which accepts this request and processes it.
b. Processing includes steps by:
i. Getting the invoice header through a CRM Service Retrieve call.
ii. Getting the Invoice Lines through a CRM Service Retrieve multiple call.
c. Commit the Invoice to the 3rd Remote Application Database.
d. We respond to the Plug-in by wrapping any custom status or error messages.
All the processes finishes in less than a minute.
Scenarios We tested on our end:
Case 1:
Invoice Containing 5-10 Lines
Steps 3(a). till 3(d). runs successfully and integrated the Invoice with all the lines.
Case 2: ISSUE
Invoice Containing more than 10 (Tested with 15-40 lines)
Step 3b(ii) . Invoice Lines Retrieval process retrieves only some lines and not all the lines
Initially we thought, there could be a Read lock for the current Authenticated user for CRM SDK, as the logged in user was also same, when the CRM is creating lines for the Invoice.
But the test failed there too.
Successful Scenario Tested:
We retrieved the Invoice Lines separately through a different call by delaying the call for some seconds. The number of lines retrieved was successful. But not sure what delay the server would take.
We require your inputs on this issue to move forward in order to resolve this as we may be making some mistakes while doing this Plugin request call.
Thanks And Regards.
I know that this question is a year old but I'm still looking for a solution to it so I figure other people might be too.
My experience is that CRM needs to save (Create) the header record before it can associate the lines to it. Because you have registered it for Async execution, there is a slight delay before it executes which gives it time to have saved some of the lines before you try and load them.
So far my best solution is to trigger the plugin on the Create message of invoicelines, count all of the lines associated with that invoice and either pass a row count from the order or count the lines on the order and when they have the same count, execute your main body of code. It is pretty inefficient for orders with a lot of rows. But it is a solution.