One of the cool side effects of Event Notifications is the easy collection of SQL Errorlog. While it doesn't collect all messages, it collects enough for me to be aware of problems. Alas, it does not collect enough for me to get an email when a server decides to shut down... the skipped messages are usually around startup/shutdown and error dumps. See https://connect.microsoft.com/SQLServer/feedback/details/782901/event-notification-not-all-errorlog-notices-are-sent-to-service-or-queue#details for more info.
BUT... since it's EN, you get them in real-time, so you could theoretically do other things with them. This report runs once a day, but I'm sure someone in the comments will come up with a new use I hadn't considered. I use Alerts on the SQL Server, but I could think of other triggers (what if you suddenly started getting failed logins?)
Another advantage: this has more than the sql ERRORLOG file has - it's closer to what the Event Logs have. Which means that you don't just got "query ran out of memory", you get the name of the login as well. REALLY handy, that.
For this report, I've just built a simple 3-way email. If there are severity errors, you get a block of those. If there are non-severity errors, they go in a different block And finally, login emails get their own.
What to do:
1) Set up EN to capture ERRORLOG. See my "Master of All I Survey" post for more. If you already have EN set up, you'll need to DROP/CREATE a new EN that includes it. (No alters, sorry)
2) Create a table with the exclusion table. This allows you to skip records you know about, without changing code.
CREATE TABLE [dbo].[EN_sql_errors_exclusion_email]
(
[id] [int] NOT NULL IDENTITY(1, 1),
[Exclusions] [varchar] (250) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[EN_sql_errors_exclusion_email] ADD CONSTRAINT [PK__EN_sql_errors__ID] PRIMARY KEY CLUSTERED ([id]) ON [PRIMARY]
GO
3) Create a job. Here's my description:
This job uses EventNotificationRec..ENAudit_Events and looks for all SQL errors since 1 day ago , split up by those that have 'severity' in the text data, those that don't, and failed logins. You can exclude data by adding rows to table EN_sql_errors_exclusion_email (uses LIKE, so 'blah%blah' will work; code already includes % at beginning & end)
Enjoy. Let me know if you have any questions or concerns.
Monday, July 29, 2013
Thursday, July 18, 2013
[SSIS] Finding your connection strings in SQL Server 2012
(update 2013/07/18: hey, grabbing the data source doesn't actually get the default value. That's stored in the same tables, but I need to figure out how to pull those out (ObjectType, maybe). Give me a few days.)
(update 2013/07/22 here's what I've cobbled together, though it needs to be integrated with the below
SELECT projects.name, ConnStr.object_name, ConnStr.parameter_name, ConnStr.description,
ConnStr.design_default_value, ConnStr.default_value,
SrvName.parameter_name, SrvName.description, SrvName.design_default_value,
SrvName.default_value,
--the catalog name
DBName.parameter_name, DBName.design_default_value, DBName.default_value
FROM ssisdb.catalog.projects
INNER JOIN [SSISDB].[catalog].[object_parameters] ConnStr
ON SSISDB.catalog.projects.project_id = ConnStr.project_id
--get the server name. Left outer join as it doesn't appear in the table otherwise
LEFT OUTER JOIN [SSISDB].[catalog].[object_parameters] SrvName
ON connstr.[object_name] = SrvName.[object_name]
AND connstr.parameter_name LIKE 'CM%ConnectionString'
AND srvname.parameter_name LIKE 'CM%ServerName'
--get the database name as well
LEFT OUTER JOIN [SSISDB].[catalog].[object_parameters] DBName
ON connstr.[object_name] = DBName.[object_name]
AND connstr.parameter_name LIKE 'CM%ConnectionString'
AND DBName.parameter_name LIKE 'CM%InitialCatalog'
WHERE ConnStr.parameter_name LIKE 'CM%ConnectionString'
AND LEFT(connstr.parameter_name, LEN(connstr.parameter_name) - CHARINDEX('.',REVERSE(connstr.parameter_name)))
= LEFT(SrvName.parameter_name, LEN(SrvName.parameter_name) - CHARINDEX('.',REVERSE(SrvName.parameter_name)))
AND LEFT(connstr.parameter_name, LEN(connstr.parameter_name) - CHARINDEX('.',REVERSE(connstr.parameter_name)))
= LEFT(DBName.parameter_name, LEN(DBName.parameter_name) - CHARINDEX('.',REVERSE(DBName.parameter_name)))
ORDER BY projects.name, ConnStr.object_name, connstr.parameter_name
)
Part of the "fun" with SSIS has always been the myriad of ways a parameter can be set. Variables, Configuration Files, Properties, Jobs.... and probably 1 or 2 others, just to confuse things.
I've already posted (http://thebakingdba.blogspot.com/2013/05/ssis-finding-your-connection-strings-in.html) about the connection strings in 2008/R2. This is the version for 2012...
In theory, it should be simple - if you're using the new methodology, you're developing with SSISDB, and using it to hold your configuration values. Thus, it has all the connection string details within.
However, it can be overridden at the job level... so you potentially need both. What I do is grab the most recent run of the package, as well as what SSISDB says it has for the package, and present both.
Let me know if there are any questions. I see on mine, for instance, dupes where the connection string is the same, but the parameter name is different. Not sure why yet.
Let me know if you see any problems or places to improve, or heck, maybe I'm just doing it wrong.
(update 2013/07/22 here's what I've cobbled together, though it needs to be integrated with the below
SELECT projects.name, ConnStr.object_name, ConnStr.parameter_name, ConnStr.description,
ConnStr.design_default_value, ConnStr.default_value,
SrvName.parameter_name, SrvName.description, SrvName.design_default_value,
SrvName.default_value,
--the catalog name
DBName.parameter_name, DBName.design_default_value, DBName.default_value
FROM ssisdb.catalog.projects
INNER JOIN [SSISDB].[catalog].[object_parameters] ConnStr
ON SSISDB.catalog.projects.project_id = ConnStr.project_id
--get the server name. Left outer join as it doesn't appear in the table otherwise
LEFT OUTER JOIN [SSISDB].[catalog].[object_parameters] SrvName
ON connstr.[object_name] = SrvName.[object_name]
AND connstr.parameter_name LIKE 'CM%ConnectionString'
AND srvname.parameter_name LIKE 'CM%ServerName'
--get the database name as well
LEFT OUTER JOIN [SSISDB].[catalog].[object_parameters] DBName
ON connstr.[object_name] = DBName.[object_name]
AND connstr.parameter_name LIKE 'CM%ConnectionString'
AND DBName.parameter_name LIKE 'CM%InitialCatalog'
WHERE ConnStr.parameter_name LIKE 'CM%ConnectionString'
AND LEFT(connstr.parameter_name, LEN(connstr.parameter_name) - CHARINDEX('.',REVERSE(connstr.parameter_name)))
= LEFT(SrvName.parameter_name, LEN(SrvName.parameter_name) - CHARINDEX('.',REVERSE(SrvName.parameter_name)))
AND LEFT(connstr.parameter_name, LEN(connstr.parameter_name) - CHARINDEX('.',REVERSE(connstr.parameter_name)))
= LEFT(DBName.parameter_name, LEN(DBName.parameter_name) - CHARINDEX('.',REVERSE(DBName.parameter_name)))
ORDER BY projects.name, ConnStr.object_name, connstr.parameter_name
)
Part of the "fun" with SSIS has always been the myriad of ways a parameter can be set. Variables, Configuration Files, Properties, Jobs.... and probably 1 or 2 others, just to confuse things.
I've already posted (http://thebakingdba.blogspot.com/2013/05/ssis-finding-your-connection-strings-in.html) about the connection strings in 2008/R2. This is the version for 2012...
In theory, it should be simple - if you're using the new methodology, you're developing with SSISDB, and using it to hold your configuration values. Thus, it has all the connection string details within.
However, it can be overridden at the job level... so you potentially need both. What I do is grab the most recent run of the package, as well as what SSISDB says it has for the package, and present both.
Let me know if there are any questions. I see on mine, for instance, dupes where the connection string is the same, but the parameter name is different. Not sure why yet.
Let me know if you see any problems or places to improve, or heck, maybe I'm just doing it wrong.
Thursday, July 11, 2013
[Replication] Fun little gotcha with tables that have a UNIQUE index/constraint.
So I've been bitching to one of our devs about how his updates to a replicated table suck. Today I went looking. What the.... it issues a delete, then inserts the row? Why are you doing it that way? Well, he's not. SQL is. : - \
Turns out, if you have a unique index or constraint (as opposed to the default PK index, I suppose...), then it deletes then inserts the row. Which sucks when you have a massive wide table with a ton of records.
Live and learn. Hopefully this helps somebody else.
https://blogs.msdn.com/b/repltalk/archive/2011/10/04/sql-server-transaction-replication-bounded-update-or-why-my-update-was-transformed-into-an-delete-insert-pair.aspx?Redirected=true
Turns out, if you have a unique index or constraint (as opposed to the default PK index, I suppose...), then it deletes then inserts the row. Which sucks when you have a massive wide table with a ton of records.
Live and learn. Hopefully this helps somebody else.
https://blogs.msdn.com/b/repltalk/archive/2011/10/04/sql-server-transaction-replication-bounded-update-or-why-my-update-was-transformed-into-an-delete-insert-pair.aspx?Redirected=true
Thursday, June 27, 2013
[SSRS] Get the SQL Query from your RDL via T-SQL
Coworker asked for this.
Basically we wanted to get the queries out of the RDLs on our Reporting Services server. I saw a post originally that discussed using the tool to pull all the RDLs off of the machine, then parsing them. Hey, waitasecond....
Immediately found the blog that showed how to use the double-convert to get back the XML. Once I had that, I started querying the XML to get out what I wanted. Now why am I getting NULL.....
So, after spending an hour banging my head against the XML and getting back NULL, I went to StackOverflow, whereupon a nice person named Mikael gave me the syntax I was looking for (thanks, Mikael!). Turns out that you have to ignore the namespace, which means your syntax can get... weird (at least compared to what I normally use).
Overall, though, pleased how it turned out. Please let me know if you have any questions, comments or if there's more stuff I should show. DataSource coming in a couple weeks; I have the code, just need to integrate it.
(Click on the "View Raw" to get the SQL in a new window. Thanks!)
Basically we wanted to get the queries out of the RDLs on our Reporting Services server. I saw a post originally that discussed using the tool to pull all the RDLs off of the machine, then parsing them. Hey, waitasecond....
Immediately found the blog that showed how to use the double-convert to get back the XML. Once I had that, I started querying the XML to get out what I wanted. Now why am I getting NULL.....
So, after spending an hour banging my head against the XML and getting back NULL, I went to StackOverflow, whereupon a nice person named Mikael gave me the syntax I was looking for (thanks, Mikael!). Turns out that you have to ignore the namespace, which means your syntax can get... weird (at least compared to what I normally use).
Overall, though, pleased how it turned out. Please let me know if you have any questions, comments or if there's more stuff I should show. DataSource coming in a couple weeks; I have the code, just need to integrate it.
(Click on the "View Raw" to get the SQL in a new window. Thanks!)
Thursday, May 30, 2013
[SSIS] Finding your connection strings in SQL Server 2008/R2
"Bad artists imitate - great artists steal" Picasso Banksy
I initially wasn't sure if this was worth posting - if you have the same problem, you've probably come across the same links. But since I don't see a soup-to-nuts version, here goes.
Problem: you're migrating servers, and need to see what SSIS packages might be affected, so you need the connection strings for all of your SSIS packages. You could open up each package and check the connections - but that's... inefficient.
If you're storing the packages on disk, you could write a short (power)shell script that would scan the SSIS package files. But if it's in MSDB, you'd need to pull the package XML out of the system tables, then parse the XML. This is for 2008/R2 (and if you're not using SSISDB in 2012). In 2012, SSISDB holds the files differently, and I'm awaiting an answer from one of the MS people on the SSIS team (thanks to Jamie Thomson sqlblog.com/blogs/jamie_thomson/ for forwarding my tweet to him)
Code cribbed from somebody, possibly Feodor Georgiev (I found two links, below)
http://sqlconcept.com/2011/12/06/extracting-ssis-package-definition-from-msdb/
https://www.simple-talk.com/content/print.aspx?article=1408
and the XML parse was a question I asked on StackOverflow. Thanks to Davmos for the help!
http://stackoverflow.com/questions/16824772/sql-server-query-xml-node-dtsconnectionmanager-dtsname-in-t-sql/16825308?noredirect=1#comment24269324_16825308
I initially wasn't sure if this was worth posting - if you have the same problem, you've probably come across the same links. But since I don't see a soup-to-nuts version, here goes.
Problem: you're migrating servers, and need to see what SSIS packages might be affected, so you need the connection strings for all of your SSIS packages. You could open up each package and check the connections - but that's... inefficient.
If you're storing the packages on disk, you could write a short (power)shell script that would scan the SSIS package files. But if it's in MSDB, you'd need to pull the package XML out of the system tables, then parse the XML. This is for 2008/R2 (and if you're not using SSISDB in 2012). In 2012, SSISDB holds the files differently, and I'm awaiting an answer from one of the MS people on the SSIS team (thanks to Jamie Thomson sqlblog.com/blogs/jamie_thomson/ for forwarding my tweet to him)
Code cribbed from somebody, possibly Feodor Georgiev (I found two links, below)
http://sqlconcept.com/2011/12/06/extracting-ssis-package-definition-from-msdb/
https://www.simple-talk.com/content/print.aspx?article=1408
and the XML parse was a question I asked on StackOverflow. Thanks to Davmos for the help!
http://stackoverflow.com/questions/16824772/sql-server-query-xml-node-dtsconnectionmanager-dtsname-in-t-sql/16825308?noredirect=1#comment24269324_16825308
Wednesday, May 22, 2013
[Powershell] Grabbing and parsing the RSS feed for new SQL Server Releases
(Updated 2019/04/18 - MS changed the site, moved to TLS 1.2)
My boss asked me to scrape a web site for release/security info for SQL Server. Okay.
First attempt required a stop at stackoverflow, where I was reminded about hashtables (Thanks again to Grainer!) And after several hours, I had found the correct Microsoft blog for security updates and had this:
cls
$posts= @() # this basically resets the posts for multiple runs - broke my ISE and good before
[xml]$rss = Invoke-WebRequest http://technet.microsoft.com/en-us/security/rss/comprehensive
$rss.SelectNodes('//item') | % {
$posts += New-Object psobject -Property @{
Title = $_.Title.Trim()
Thedate = [datetime]$_.date.Trim()
Guid = $_.Guid.Trim()
Content = $_.Encoded."#cdata-section".Trim()
}
}
$posts | select-object # | where-object {$_.Title -like '*sql*' -or $_.Guid -like '*sql*'}
#and then insert into a table
Awesome! I feel good - mission accomplished. Worked on it at home (yes, nerd here, big shock).
Then the boss looks and says "no, I didn't want that, I wanted the patches and CUs".
Crap. So let's go find a different blog. Oh yeah, I have one specifically for SP/CUs! (In google reader, naturally...RIP. OT: go to Newsblur and CommaFeed!)
Fortunately, this blog is much easier to parse, so I don't need the hashtable. Well, not a massive hashtable. The second one below is specifically to rename the "Description" field so that I don't have a field that's a semi-reserved word. The first one below is to reformat it as a datetime. Use Chad Miller's awesome scripts to turn it into a datatable and write to disk, and voila! (Alternatively, you should be able to use my Extensible Powershell Repository, elsewhere on this blog, and just have a 2-line PS script that is invoked via the EPR.
Now, I just have to use that with a MERGE statement to add only the new records, and email me when a new record comes in.
# CREATE TABLE SQL_Server_Releases_from_RSS
#(
# title varchar(200),
# link varchar(500),
# pubdate smalldatetime,
# descript varchar(MAX) --I really don't want a field named "description"
#)
# Scripts from http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx
. C:\sql_tools\out-datatable.ps1 #Chad Miller rocks!
. C:\sql_tools\write-datatable.ps1
. C:\sql_tools\add-sqltable.ps1
#the next line, fixing the TLS ("could not create SSL/TLS secure channel") fixed by Chandan Rai on https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel
[xml]$rss = Invoke-WebRequest https://techcommunity.microsoft.com/gxcuf89792/rss/board?board.id=SQLServer -UseBasicParsing #was http://blogs.msdn.com/sqlreleaseservices/rss.xml, changed by mdb on 2018/03/19
$datatable = $rss.rss.channel.item | select title, link, @{Name="pubdate";Expression={get-date ($_.date) -format "yyyy/MM/dd hh:mm"}}, @{Name="descript";Expression={$_."Description"}} |out-datatable
write-datatable -ServerInstance "sql_repository" -Database myrepository -TableName SQL_Server_Releases_from_RSS -data $datatable
My boss asked me to scrape a web site for release/security info for SQL Server. Okay.
First attempt required a stop at stackoverflow, where I was reminded about hashtables (Thanks again to Grainer!) And after several hours, I had found the correct Microsoft blog for security updates and had this:
cls
$posts= @() # this basically resets the posts for multiple runs - broke my ISE and good before
[xml]$rss = Invoke-WebRequest http://technet.microsoft.com/en-us/security/rss/comprehensive
$rss.SelectNodes('//item') | % {
$posts += New-Object psobject -Property @{
Title = $_.Title.Trim()
Thedate = [datetime]$_.date.Trim()
Guid = $_.Guid.Trim()
Content = $_.Encoded."#cdata-section".Trim()
}
}
$posts | select-object # | where-object {$_.Title -like '*sql*' -or $_.Guid -like '*sql*'}
#and then insert into a table
Awesome! I feel good - mission accomplished. Worked on it at home (yes, nerd here, big shock).
Then the boss looks and says "no, I didn't want that, I wanted the patches and CUs".
Crap. So let's go find a different blog. Oh yeah, I have one specifically for SP/CUs! (In google reader, naturally...RIP. OT: go to Newsblur and CommaFeed!)
Fortunately, this blog is much easier to parse, so I don't need the hashtable. Well, not a massive hashtable. The second one below is specifically to rename the "Description" field so that I don't have a field that's a semi-reserved word. The first one below is to reformat it as a datetime. Use Chad Miller's awesome scripts to turn it into a datatable and write to disk, and voila! (Alternatively, you should be able to use my Extensible Powershell Repository, elsewhere on this blog, and just have a 2-line PS script that is invoked via the EPR.
Now, I just have to use that with a MERGE statement to add only the new records, and email me when a new record comes in.
# CREATE TABLE SQL_Server_Releases_from_RSS
#(
# title varchar(200),
# link varchar(500),
# pubdate smalldatetime,
# descript varchar(MAX) --I really don't want a field named "description"
#)
# Scripts from http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx
. C:\sql_tools\out-datatable.ps1 #Chad Miller rocks!
. C:\sql_tools\write-datatable.ps1
. C:\sql_tools\add-sqltable.ps1
#the next line, fixing the TLS ("could not create SSL/TLS secure channel") fixed by Chandan Rai on https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#web page changed by MS, yet again, around 2019/04/15. Also moved to TLS 1.2.[xml]$rss = Invoke-WebRequest https://techcommunity.microsoft.com/gxcuf89792/rss/board?board.id=SQLServer -UseBasicParsing #was http://blogs.msdn.com/sqlreleaseservices/rss.xml, changed by mdb on 2018/03/19
write-datatable -ServerInstance "sql_repository" -Database myrepository -TableName SQL_Server_Releases_from_RSS -data $datatable
Thursday, May 16, 2013
[Extended Events] list of predicates that you can use to filter actions
I've been using XE lately to get a list of servers that connect to a server I'm going to upgrade (see http://thebakingdba.blogspot.com/2013/04/extended-events-what-servers-are.html). That way I know what the downstream effects are beforehand.
However, these are busy servers - even with connection pooling, we can get hundreds of connections a minute. Which means even minimal logging will get big, fast.
So there are two ways to prevent that:
So, back to #1, and looking at Predicates.
Fortunately, I found this blog post which has a lot of details about it:
http://blogs.msdn.com/b/extended_events/archive/2010/06/24/today-s-subject-predicates.aspx
(yup, a 2-year-old post that's now incredibly relevant)
Specifically,
SELECT name, description,
(SELECT name FROM sys.dm_xe_packages WHERE guid = o.package_guid) package
FROM sys.dm_xe_objects o
WHERE object_type = 'pred_compare'
ORDER BY name
Which lead me to:
sqlserver.like_i_sql_unicode_string
From the blog post:
"Calling a pred_compare directly follows this syntax:
"
Okay, I can do that.
WHERE (
(sqlserver.like_i_sql_unicode_string(sqlserver.client_hostname,N'laptop%'))
)
which gives me everything from our laptops. Close. Can I do a NOT LIKE?
WHERE (
(NOT sqlserver.like_i_sql_unicode_string(sqlserver.client_hostname,N'laptop%'))
)
Which, yes, works.
So my query to look for logins not from our laptops, and excluding certain servers, looks like...
CREATE EVENT SESSION [Logins] ON SERVER
ADD EVENT sqlserver.login(
ACTION(sqlserver.client_hostname,sqlserver.client_app_name,sqlserver.database_name)
WHERE ([sqlserver].client_hostname NOT LIKE '%-SERV-%')
AND (NOT sqlserver.like_i_sql_unicode_string(sqlserver.client_hostname,N'laptop%'))
)
ADD TARGET package0.ring_buffer(SET max_memory = 4096)
And, typing this in... I see I'm already excluding using a LIKE. Why'd I go through all this effort again? Um, knowledge, I guess? : )
However, these are busy servers - even with connection pooling, we can get hundreds of connections a minute. Which means even minimal logging will get big, fast.
So there are two ways to prevent that:
- Predicates to filter before it hits the target
- Using a histogram to store in buckets.
So, back to #1, and looking at Predicates.
Fortunately, I found this blog post which has a lot of details about it:
http://blogs.msdn.com/b/extended_events/archive/2010/06/24/today-s-subject-predicates.aspx
(yup, a 2-year-old post that's now incredibly relevant)
Specifically,
SELECT name, description,
(SELECT name FROM sys.dm_xe_packages WHERE guid = o.package_guid) package
FROM sys.dm_xe_objects o
WHERE object_type = 'pred_compare'
ORDER BY name
Which lead me to:
sqlserver.like_i_sql_ansi_string
sqlserver.like_i_sql_unicode_string
From the blog post:
"Calling a pred_compare directly follows this syntax:
package_name.pred_compare(field/pred_source, value)[...]ADD EVENT wait_info (WHERE package0.greater_than_max_int64(duration, 500)
"
Okay, I can do that.
WHERE (
(sqlserver.like_i_sql_unicode_string(sqlserver.client_hostname,N'laptop%'))
)
which gives me everything from our laptops. Close. Can I do a NOT LIKE?
WHERE (
(NOT sqlserver.like_i_sql_unicode_string(sqlserver.client_hostname,N'laptop%'))
)
Which, yes, works.
So my query to look for logins not from our laptops, and excluding certain servers, looks like...
CREATE EVENT SESSION [Logins] ON SERVER
ADD EVENT sqlserver.login(
ACTION(sqlserver.client_hostname,sqlserver.client_app_name,sqlserver.database_name)
WHERE ([sqlserver].client_hostname NOT LIKE '%-SERV-%')
AND (NOT sqlserver.like_i_sql_unicode_string(sqlserver.client_hostname,N'laptop%'))
)
ADD TARGET package0.ring_buffer(SET max_memory = 4096)
And, typing this in... I see I'm already excluding using a LIKE. Why'd I go through all this effort again? Um, knowledge, I guess? : )
Thursday, May 2, 2013
[SSIS 2012] Using SQL Sentry & custom code to send detailed email on failure
(update 2013/07/31 dealing with "cancelled")
This is a simple modification of http://thebakingdba.blogspot.com/2012/11/sql-server-2012-ssis-getting-useful.html, which sends an email with specific job failure info, rather than the nondescript "To view the details for the execution, right-click on the Integration Services Catalog, and open the [All Executions] report ", which is pretty freaking useless.
We use SQL Sentry, which makes this part simple (they have their own method of logging SSIS failures, but it has several prereqs I don't like - specifically, it changes the step from SSIS to CmdExec, and executes the parameter-laden string). My original post/SP required you to add a job step to each job - this one gets set on the server. Just add an SQL Sentry action ("SQL Server Job Agent: Failure") and add "Execute SQL", running the following code, and it takes care of every job on the server.
exec yourdbname.dbo.ssis_job_failure_info_fromjobname @job_name = '<%ObjectName%>'
As a bonus, I use the SQL Sentry email SP, so it appears to come from
SQL Sentry. That could be useful for you, based on your filtering.
One note: if the job fails because of an SSIS timeout (see: http://connect.microsoft.com/SQLServer/feedback/details/725840/catalog-executions-getting-cancelled-without-logging-any-error), no email is sent. That's because, while the job failed, technically the package doesn't know it failed... or something like that. Read the Connect item for more details. Supposedly fixed in SP1,but haven't had it happen up to now. but if it happens to you, there are a handful of fixes available.
And here's the modified SP:
This is a simple modification of http://thebakingdba.blogspot.com/2012/11/sql-server-2012-ssis-getting-useful.html, which sends an email with specific job failure info, rather than the nondescript "To view the details for the execution, right-click on the Integration Services Catalog, and open the [All Executions] report ", which is pretty freaking useless.
We use SQL Sentry, which makes this part simple (they have their own method of logging SSIS failures, but it has several prereqs I don't like - specifically, it changes the step from SSIS to CmdExec, and executes the parameter-laden string). My original post/SP required you to add a job step to each job - this one gets set on the server. Just add an SQL Sentry action ("SQL Server Job Agent: Failure") and add "Execute SQL", running the following code, and it takes care of every job on the server.
exec yourdbname.dbo.ssis_job_failure_info_fromjobname @job_name = '<%ObjectName%>'
(where yourdbname is wherever you store the SP)
One note: if the job fails because of an SSIS timeout (see: http://connect.microsoft.com/SQLServer/feedback/details/725840/catalog-executions-getting-cancelled-without-logging-any-error), no email is sent. That's because, while the job failed, technically the package doesn't know it failed... or something like that. Read the Connect item for more details. Supposedly fixed in SP1,
- Add the 5 indexes as per http://www.ssistalk.com/2013/01/31/ssis-2012-catalog-indexing-recommendations/
- Change Retention period as per: http://www.made2mentor.com/2013/02/setup-and-performance-issues-with-the-integration-services-ssis-2012-catalog/
- Don't just set it to 90 if you have a lot of history! You need to iterate through days, running the maint job between each.
- Change DB size settings as per same post
- Ensure Database is in SIMPLE mode.
- (possibly turn on snapshot isolation)
- (I also turn on Async Statistics Update)
- http://support.microsoft.com/kb/2829948 - There is a fix from MS! SP1 CU4 has a fix. It says it just adds indexes; it must change the delete SP, since adding the indexes did NOT fix it for me.
And here's the modified SP:
Friday, April 19, 2013
[WAT] bizarrreness with ISNULL
Coworker came across this, and even found an article by Aaron Bertrand about it.
But the practical takeaway we had today, from Aaron's code - ISNULL can cause truncation:
DECLARE @c5 VARCHAR(5); SELECT 'COALESCE', COALESCE(@c5, 'longer name') UNION ALL SELECT 'ISNULL', ISNULL(@c5, 'longer name');
Wednesday, April 17, 2013
[Extended Events] What servers are connecting to my SQL Server 2012 box?
(code is complete, soup-to-nuts, but only runs on 2012; I'll modify it for 2008/R2 in another post.)
(update 2013/04/18 Jonathan Kehayias helpfully provided a way to do it by adding the existing_connection event - but there appears to be a bug with the histogram, and it doesn't return the right data. Connect item if you want to vote on it: https://connect.microsoft.com/SQLServer/feedback/details/785042/extended-events-histogram-does-not-properly-save-existing-connection-results)
First of all, MANY thanks to Jonathon Kehayias for all the XE wisdom and code - I modified the snot out of his http://www.sqlskills.com/blogs/jonathan/tracking-sql-server-database-usage/ lock-tracking-using-a-histogram to build this...
Say I want to figure out what servers are connecting to my SQL Server. This is something you'd traditionally either poll sysprocesses for periodically, or probably run a trace. Both have issues, though, especially if they're busy servers. So, how can we get that? Extended Events.
The easiest way to do this would be using Extended Events - create a "bucketizer" (now called the histogram), and watch for new logins, saving the servername and incrementing a counter each time it happens. As a bonus, we could then filter it - exclude particular applications, servers, etc (see the commented out code). And, since it's a pretty basic XE, overhead is very low. The one caveat is that you can only get one piece of information out - servername. I'd LOVE to get the App Name & DB Name as well, but you can only get one piece of information at a time. Downer. : - (
One caveat: If you have servers that stay connected, and don't open new connections, you won't see them here. The obvious exclusion, then, is replication, but maybe your app hangs on for a long time (we've seen that with third-party tools). Easy answer for those is to use SP_WHOISACTIVE.
Any questions?
(update 2013/04/18 Jonathan Kehayias helpfully provided a way to do it by adding the existing_connection event - but there appears to be a bug with the histogram, and it doesn't return the right data. Connect item if you want to vote on it: https://connect.microsoft.com/SQLServer/feedback/details/785042/extended-events-histogram-does-not-properly-save-existing-connection-results)
First of all, MANY thanks to Jonathon Kehayias for all the XE wisdom and code - I modified the snot out of his http://www.sqlskills.com/blogs/jonathan/tracking-sql-server-database-usage/ lock-tracking-using-a-histogram to build this...
Say I want to figure out what servers are connecting to my SQL Server. This is something you'd traditionally either poll sysprocesses for periodically, or probably run a trace. Both have issues, though, especially if they're busy servers. So, how can we get that? Extended Events.
The easiest way to do this would be using Extended Events - create a "bucketizer" (now called the histogram), and watch for new logins, saving the servername and incrementing a counter each time it happens. As a bonus, we could then filter it - exclude particular applications, servers, etc (see the commented out code). And, since it's a pretty basic XE, overhead is very low. The one caveat is that you can only get one piece of information out - servername. I'd LOVE to get the App Name & DB Name as well, but you can only get one piece of information at a time. Downer. : - (
One caveat: If you have servers that stay connected, and don't open new connections, you won't see them here. The obvious exclusion, then, is replication, but maybe your app hangs on for a long time (we've seen that with third-party tools). Easy answer for those is to use SP_WHOISACTIVE.
Any questions?
Subscribe to:
Posts (Atom)