YouTube2Text

SQL Server Integration Services (SSIS) Part 17 - Event-handling and logging — Transcript

by WiseOwlTutorials · 3,085 words · 450 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:00Welcome to this Weisowl tutorial on
  3. 0:02event handling and logging in SQL Server
  4. 0:05Integration Services. Here's what we'll
  5. 0:07learn on the tutorial.
  6. 0:09We'll begin by having a look at event
  7. 0:11handling within integration services.
  8. 0:13So, we'll look at how to create event
  9. 0:14handlers, how to review the ones you've
  10. 0:16already got set up, and how to get
  11. 0:18variables to raise events when their
  12. 0:20values change.
  13. 0:22We'll then go on to look at logging. So,
  14. 0:24we'll look at the main types of logging
  15. 0:25available to you, how to log information
  16. 0:27on a package's execution progress to
  17. 0:30text files, and how to do the same thing
  18. 0:32to a SQL Server table. And finally,
  19. 0:35we'll have a quick look at audit
  20. 0:36transforms, which provide another way to
  21. 0:39log information about what's going on
  22. 0:40within your package. So, let's get
  23. 0:43started.
  24. 0:45To illustrate the concept of event
  25. 0:48handlers and how to make them work
  26. 0:49within integration services, I've
  27. 0:51created a really simple package which
  28. 0:53imports from an Excel worksheet the
  29. 0:55number of series, imports a number of
  30. 0:57mentors and stores those two bits of
  31. 0:59information in variables called number
  32. 1:00mentors and number series. What the
  33. 1:03script then does is display the result
  34. 1:05of those two variables. If I run this
  35. 1:08package, you'll see that it comes up
  36. 1:10with a dialog box saying I've imported
  37. 1:11nine series and 10 mentors. The precise
  38. 1:15details of how these two data flow tasks
  39. 1:17work isn't terribly important, but just
  40. 1:20for the sake of your curiosity, I'll
  41. 1:21show you one of them. It takes in an
  42. 1:23Excel worksheet and uses a row count
  43. 1:25transform to store the number of rows in
  44. 1:28a variable.
  45. 1:31It works, but you could argue that this
  46. 1:34uh script task isn't actually part of
  47. 1:36the control flow at all. It's just
  48. 1:38almost like a debug message which is
  49. 1:40popping up on screen to say that
  50. 1:41everything's worked successfully.
  51. 1:43This would be even truer if I had used
  52. 1:45something like a send mail task, in
  53. 1:47which case I really would just be
  54. 1:49reporting on the progress of what's
  55. 1:50happening without it necessarily being
  56. 1:52part of my control flow. So what I'm
  57. 1:55going to do is show you an alternative
  58. 1:56way to achieve the same thing using an
  59. 1:58event handler and then we can decide
  60. 2:00whether or not it's better.
  61. 2:02To do that, I'll just cut that to my
  62. 2:04clipboard clipboard. I'm going to need
  63. 2:06it soon. And I'll connect these two
  64. 2:09tasks up together so they run in
  65. 2:10sequence.
  66. 2:12What I want to do is say that when this
  67. 2:13get number of mentors task has finished
  68. 2:15executing then I want my message to
  69. 2:18appear. So what I'm going to do is go to
  70. 2:20the event handlers tab and click on the
  71. 2:23drop on the left hand side and choose to
  72. 2:26which task or which package I want to
  73. 2:28attach an event.
  74. 2:30Now because I have the get number of
  75. 2:32mentors selected, it's chosen that
  76. 2:34automatically. But I could attach an
  77. 2:36event to any one of these different
  78. 2:37parts of my package. So I'll choose
  79. 2:40that. I can then choose the event and
  80. 2:43there are three main ones you'll choose
  81. 2:44typically which are pre-execute which
  82. 2:47runs immediately before the task runs
  83. 2:49postexecute runs immediately after it
  84. 2:52has finished executing and on error is
  85. 2:54fairly self-explanatory.
  86. 2:57So I'm going to choose postexecute and I
  87. 3:00now need to click to create my
  88. 3:01postexecute event handler.
  89. 3:04If you're expecting something dramatic
  90. 3:05to happen at this point you'll be
  91. 3:06disappointed. All it does is clear the
  92. 3:08screen. I've got an event handler. You
  93. 3:11can see that because it's gone bold in
  94. 3:12my list, but it's not actually doing
  95. 3:14anything. So, what I'll do is paste in
  96. 3:17my script task there. And if I now go
  97. 3:19back to my control flow, you'll see that
  98. 3:22when I run this um package, when I
  99. 3:24finished executing this second task, my
  100. 3:27event handler will kick in and display
  101. 3:29exactly the same dialog box as we saw
  102. 3:31earlier. So, let's see if this works. I
  103. 3:34run my package.
  104. 3:36It's finished executing the second task.
  105. 3:38And lo and behold, my event handler has
  106. 3:40displayed the dialogue box.
  107. 3:44As to whether it's better or not, I
  108. 3:46leave that up to you. Personally, I
  109. 3:48think it's much clearer if I have
  110. 3:50everything in my control flow and I
  111. 3:52don't like the fact that something's
  112. 3:53hidden away in an event handler, but you
  113. 3:55may disagree.
  114. 3:59In the previous part of this tutorial, I
  115. 4:02created an event handler for the get
  116. 4:04number of menus tasks postexecute event.
  117. 4:08What I want to do now is see how you can
  118. 4:09see to which which event handlers you've
  119. 4:11created for which part of a package.
  120. 4:14One way to do that of course is to click
  121. 4:16on the event handlers tab and then click
  122. 4:18on the part of the package you're
  123. 4:20interested in. So if you're clairvoyant
  124. 4:22or have a bit of insight, you could
  125. 4:24guess that you've attached something to
  126. 4:26the get number of menus task and when
  127. 4:29you choose okay you'll see the
  128. 4:30suspicions were correct because it
  129. 4:32appears in bold in the the on
  130. 4:34postexecute event appears in bold in the
  131. 4:36list. You can then click on that and see
  132. 4:38what that event is doing.
  133. 4:41What would be nice though is to have
  134. 4:43some holistic approach where you can see
  135. 4:44everything in one place and it's called
  136. 4:46package explorer
  137. 4:48and you can see there that you can
  138. 4:50expand um the executables which are
  139. 4:53essentially the tasks within a package
  140. 4:55to see the events attached to each of
  141. 4:57them. If we look at the get number of
  142. 4:59series task it's got no event handlers
  143. 5:02attached to it. But if we look at the
  144. 5:04get number of mentors task you can see
  145. 5:06it has got event handlers attached.
  146. 5:09In fact, the only events are attached to
  147. 5:11the onpost execute event. And you can
  148. 5:14expand that to see what the event
  149. 5:16handlers are. It's a bit disturbing to
  150. 5:19see that the event handlers have
  151. 5:21themselves potential to have event
  152. 5:22handlers. I don't even want to go there.
  153. 5:26So, that's how you can use package
  154. 5:27explorer to review the events you've
  155. 5:29attached to different parts of a
  156. 5:31package.
  157. 5:34So far, we've got normal event handlers
  158. 5:36working. What I want to do now is show
  159. 5:38that you can get SIS to react to when a
  160. 5:40variable values has changed. But I
  161. 5:43should warn you, it's quite complicated
  162. 5:44and there's so many things which can go
  163. 5:46wrong that you might want not to bother
  164. 5:49doing it. Let's have a look at our
  165. 5:51package we've got. I've got a variable
  166. 5:53called answer which holds the value zero
  167. 5:55initially and I've got an expression
  168. 5:57task which changes the value of the
  169. 5:59variable to 42 which is the meaning of
  170. 6:01life as we all know. I've then got a
  171. 6:03script which displays the value of that
  172. 6:05variable. So if I run this package, what
  173. 6:07I'll get is a message saying the meaning
  174. 6:09of life is 42. So far so good. What I
  175. 6:13want to do now is get the script to run
  176. 6:16when the value of this variable called
  177. 6:18answer changes. And that should be
  178. 6:20fairly straightforward. I should be able
  179. 6:22to cut this script, go to my event
  180. 6:24handlers and attach it to the on
  181. 6:27variable value changed of the meaning of
  182. 6:30life task.
  183. 6:33If I click on that, it will create the
  184. 6:35event and I can paste in my script.
  185. 6:38And surely that's job done. Let's find
  186. 6:41out. If I run this package now, you'll
  187. 6:43see that absolutely nothing happens. No
  188. 6:45script runs. And the reason for that is
  189. 6:49because my variable isn't telling the
  190. 6:51world its value has been changed because
  191. 6:53by default variables don't. So what I
  192. 6:56need to do is find a column in here
  193. 6:57saying whether the value of the variable
  194. 6:59being changed will raise an event. And I
  195. 7:01can do that by going to the grid options
  196. 7:03and choosing to display the raise event
  197. 7:05when variable value changes column.
  198. 7:07Obviously
  199. 7:09the default for that is false. So I'm
  200. 7:11going to change it to true.
  201. 7:13And the variables value changing should
  202. 7:16now raise an event which should be
  203. 7:17handled and I should see my message,
  204. 7:20shouldn't I? But if I run it, I think
  205. 7:22we'll see still nothing happens.
  206. 7:25The problem now is that the scope of the
  207. 7:27variable is for the entire package, but
  208. 7:30it's trying to raise an event within a
  209. 7:32specific task. So, what I need to do is
  210. 7:35to click on the move variable but icon
  211. 7:38and move my variable within the task.
  212. 7:43The variable disconcertingly vanishes,
  213. 7:45but that's cuz I haven't got my task
  214. 7:46selected. Once I do that, you can see
  215. 7:48that it reselects it or redis it. The
  216. 7:52really nasty bug is it resets this raise
  217. 7:56change uh property back to false which I
  218. 7:59must admit took me a long time to
  219. 8:00notice. So I need to change it back to
  220. 8:02true otherwise the variables value being
  221. 8:04changed won't raise an event. And surely
  222. 8:08surely now it's all going to work. Well
  223. 8:11sort of. It's clearly running an event
  224. 8:14but what it's not doing is displaying
  225. 8:15the script. And at this point I'm going
  226. 8:18to go to guesswork.
  227. 8:20I think what's happening is this. I
  228. 8:23think for some reason a script within an
  229. 8:26event handler raised from this
  230. 8:28particular type of event can't pass in
  231. 8:31the variable into it. So what I'm going
  232. 8:34to do is delete the variable, edit the
  233. 8:36script, and cheat. So instead of
  234. 8:39displaying a message giving the value of
  235. 8:41the variable, what I'm actually going to
  236. 8:44do is comment that out and instead just
  237. 8:47display that the meaning of life is 42.
  238. 8:53And I think if I now run this,
  239. 8:57the variable value changed will raise an
  240. 9:00event and display that message.
  241. 9:04And that's how you can get a value of a
  242. 9:06variable being changed to raise an
  243. 9:08event.
  244. 9:11I've created an extremely complicated
  245. 9:14package. It sets a variable to one and
  246. 9:17then displays the value of the variable.
  247. 9:19And if I run this package, you can see I
  248. 9:21get an error, sorry, a dialog box saying
  249. 9:23the value of the variable is one. That
  250. 9:25was English sarcasm, by the way, if you
  251. 9:27were wondering.
  252. 9:29What I now want to do is to log what's
  253. 9:31going on. So I can look at a a trace
  254. 9:33from the executing the package and track
  255. 9:36down any errors. There's a couple of
  256. 9:39ways I could do this. A couple of
  257. 9:40obvious ways. One is to create a text
  258. 9:42file. That's the sort of thing I might
  259. 9:44get as a result. So give me lots and
  260. 9:46lots of information about what's going
  261. 9:47on. And an alternative idea might be to
  262. 9:50use SQL Server. So I've got here
  263. 9:56the output from logging. And you can see
  264. 9:58I've already accumulated 852 rows of all
  265. 10:01sorts of useful information. The
  266. 10:03advantage of SQL Server is of course
  267. 10:05that I can then write queries against
  268. 10:06it.
  269. 10:08Here are the types of logging available.
  270. 10:10You can invoke logging as I'll show
  271. 10:12shortly by choosing SSIS from the menu
  272. 10:14and choosing logging. The logging
  273. 10:16providers you can use are you can send
  274. 10:19information to a text file. You can send
  275. 10:22it to a predetermined SQL server table
  276. 10:24and I'll show you how to do that
  277. 10:25shortly. You can use SQL Server Profiler
  278. 10:29and what that does is produce a SQL
  279. 10:31profiler trace file about which I know
  280. 10:33virtually nothing I'll be honest. You
  281. 10:36can send information to the Windows
  282. 10:37event log and what it will do is log it
  283. 10:40under the source name SQLIS package 1110
  284. 10:45or you can send it to an XML file. I'm
  285. 10:48going to show the first two.
  286. 10:51So what we'll do now is set up logging
  287. 10:53to send information to a text file.
  288. 10:59To log to a text file, the first thing
  289. 11:02to do is go to SSIS and choose logging.
  290. 11:06What I can then do is choose which sort
  291. 11:09of provider I want. In this case, it's a
  292. 11:11text file one and add that into the list
  293. 11:13of providers.
  294. 11:15Before I can use it, I need to configure
  295. 11:17it. So, I need to choose a file
  296. 11:18connection. But because I don't have one
  297. 11:20set up for this project package, I'm
  298. 11:22going to have to create a new one. I'm
  299. 11:24going to choose an existing file. I'm
  300. 11:26not going to create one, although I
  301. 11:27could. And I'm going to browse to my
  302. 11:29file called log.txt and use that. So,
  303. 11:33I'm sending information to that file.
  304. 11:35But at the moment, I'm not actually
  305. 11:37logging anything. So, what I need to do
  306. 11:39is choose which bits of the package I'm
  307. 11:42going to log information for. Whether
  308. 11:44it's the entire package, whether it's
  309. 11:46the individual tasks within it, or
  310. 11:48whether it's a combination of both. as
  311. 11:49here.
  312. 11:51It still won't work because I now need
  313. 11:53to choose to tick the login provider
  314. 11:56which I've created so that it actually
  315. 11:57uses it. And then I could do with going
  316. 12:00into the details tab to fine-tune
  317. 12:03exactly what's going on. At the moment
  318. 12:05it's not capturing information for any
  319. 12:07of these events. What I want to do is
  320. 12:09after every task or and the package
  321. 12:11itself completes I want to capture the
  322. 12:14information from the onostexecute event.
  323. 12:16So I'll tick that. And I could, if I
  324. 12:19like, go into much more detail on the
  325. 12:20advanced tab and choose which bits of
  326. 12:23information I want to capture. So for
  327. 12:24example, if I don't want the operator, I
  328. 12:26could just untick that. You can never
  329. 12:28accuse SSIS of not giving you enough
  330. 12:30logging information.
  331. 12:32What I could do if I wanted is save that
  332. 12:34as an XML file so that I could then
  333. 12:37retrieve it later on for a different
  334. 12:38package. But I'm happy with what I've
  335. 12:40done. And what I'm going to do is choose
  336. 12:42okay and then run it. And what it will
  337. 12:44do is run marginally more slowly because
  338. 12:46it's actually writing out text
  339. 12:48information to that file called log.txt
  340. 12:51which I'm actually going to ask you to
  341. 12:52believe. So I can stop running and what
  342. 12:55I'll do now is show you how to log to
  343. 12:57SQL Server.
  344. 13:00The way you log to SQL Server is almost
  345. 13:02identical to the way you log to a text
  346. 13:04file. The first thing to do is choose
  347. 13:06SSIS from the menu and choose logging
  348. 13:08and then choose the type of provider you
  349. 13:10want to use. In this case is SQL Server.
  350. 13:13I need to add that into my list of
  351. 13:14providers and probably at this point
  352. 13:16untick the text one and choose to use
  353. 13:18SQL Server instead. Although there's
  354. 13:20nothing to stop me using both. I can
  355. 13:23choose here the scope of what I want to
  356. 13:24log. I'm just going to log information
  357. 13:26for the package rather than also for the
  358. 13:28individual tasks within it. And I need
  359. 13:31to configure my SQL server log provider
  360. 13:32to say which database is going to. So
  361. 13:35I've got a connection to the XFactor
  362. 13:36database and I'll use that. I can then
  363. 13:39go into details and specify which events
  364. 13:42I'm going to log information for. I'll
  365. 13:44choose both on postexecute and on
  366. 13:46pre-execute.
  367. 13:47And I'll click on the advance button and
  368. 13:49choose the fact I actually don't again
  369. 13:52want to log the operator. I'm not quite
  370. 13:53sure why, but I don't like it. I can
  371. 13:56then choose okay to confirm that and run
  372. 13:59my package. And again, it will run
  373. 14:01marginally more slowly because not only
  374. 14:03is it doing what the package does, it's
  375. 14:05also writing information out to a SQL
  376. 14:06server table. as to where that table is.
  377. 14:10Let's have a look.
  378. 14:12In object explorer, you've got your
  379. 14:14database called Xactor
  380. 14:16and within that you've got tables and
  381. 14:19within those you have system tables. And
  382. 14:21what SSIS will automatically do is
  383. 14:23create a new table called SIS SSIS log
  384. 14:26and put your logging information in
  385. 14:27that.
  386. 14:29And if you have a look at that table,
  387. 14:31you can see that it's got all sorts of
  388. 14:33wonderful information in there um to be
  389. 14:36investigated and researched.
  390. 14:39And that's how you log information to
  391. 14:41SQL Server.
  392. 14:45In addition to all the other ways of
  393. 14:46logging in information integration
  394. 14:48services such as using logging itself
  395. 14:50and using events, you can also use a
  396. 14:53nifty little transform called the audit
  397. 14:54transform. And this final part of the
  398. 14:56tutorial explains how this works. I've
  399. 14:59got a package which imports some Excel
  400. 15:01uh contestants and uses a union all
  401. 15:05transform to display the information.
  402. 15:06And I've got a data viewer which is
  403. 15:08going to show what's going down that
  404. 15:10pipeline. And you can see there's 109
  405. 15:12rows and you can see it's put in the
  406. 15:14columns coming from the Excel workbook.
  407. 15:17There's about six of them. What I'm now
  408. 15:19going to do is firstly to stop debugging
  409. 15:22and I'll get rid of this pipe. And what
  410. 15:26I'm going to do is put in an audit
  411. 15:28transform between the two. I'll connect
  412. 15:31all that up.
  413. 15:34So the information flows from the Excel
  414. 15:35workbook into the order transform and
  415. 15:37from there into the union all transform.
  416. 15:40But what the order transform will do
  417. 15:41when I configure it is add in additional
  418. 15:44columns.
  419. 15:45I'm going to choose to display the name
  420. 15:47of the package and I'm going to call
  421. 15:49that package name the default. And I'm
  422. 15:52also going to choose to display the name
  423. 15:54of the task and I'm going to call that
  424. 15:57name of task just to prove that I don't
  425. 16:00have to stick with the preset names. And
  426. 16:02there's all sorts of other information I
  427. 16:04could choose to display at the same
  428. 16:06time.
  429. 16:08If I now put a data viewer on this final
  430. 16:10stage, when I run this, I'll have two
  431. 16:12additional columns of information
  432. 16:14available to me. I'll have, yes, the
  433. 16:16columns from the original Excel
  434. 16:17workbook, but scrolling across to the
  435. 16:19right, I've also got the package name
  436. 16:21and the name of the task. At this point,
  437. 16:23I probably could have chosen more useful
  438. 16:25information because they're always the
  439. 16:27same.
  440. 16:29And that's what an ordered transform
  441. 16:31lets you do. And that completes this
  442. 16:33tutorial on logging and event handling
  443. 16:36in integration services. We hope you've
  444. 16:39enjoyed this tutorial on event handling
  445. 16:42and logging in SQL Server integration
  446. 16:44services. There's loads more training
  447. 16:46resources on SQL Server.net, Microsoft
  448. 16:49Office, and all sorts of other software
  449. 16:50applications at www.wisowl.co.uk.
  450. 16:55[Music]

About this transcript

This page contains the full transcript of SQL Server Integration Services (SSIS) Part 17 - Event-handling and logging by WiseOwlTutorials, generated from the public captions YouTube serves with the video. The transcript has 3,085 words across 450 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.

What you can do with it

Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.

Free YouTube transcript tool

YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.