Adventures in Database Administration
Monday, May 13, 2013
Word Wrap Annotation in SSIS
I thought I would pass this on since there is no word wrap feature for annotations in SSIS. If you use CTRL+Enter inside the annotation box, SSIS will drop down to the next line to begin typing.
Labels:
Annotation,
server,
SQL,
SSIS,
Tips
Wednesday, November 21, 2012
SQL Error in the Post Snapshot File for Transactional Replication
When using replication, it is sometimes useful to run a set
of commands on the subscribing database either before or after the initial
snapshot has been applied. By using a pre-snapshot file, a DBA could remove any
dependencies in the subscribing database that would keep the table from being
dropped in the event of a re-initialization. We use post-snapshot files to
create indexes on the subscribing database that do not exist on the publisher.
To find out whether or not pre/post snapshot files are being used, right click
on the publication and choose properties. From there, select snapshot and look
under the “Run additional scripts” section.
So when the subscription is initialized, a snapshot is
prepared and placed in the default folder. Along with the bulk copy files, any
pre or post snapshot files you are using are placed in there too. So the
snapshot is applied to the subscriber and, in this case, a post-snapshot script
is ran against the subscribing database. While the snapshot and the post-snapshot
scripts are being ran, updates to the replicated tables are being queued for
replication in the distribution database. These will be replicated to the
subscriber once the snapshot has been applied and the post-snapshot script has completed.
But what happens in the event that the post-snapshot script
has an error? The distribution agent considers this to be a failure and retries
the post-snapshot script over and over again. While this is happening, updates
that are queued for distribution are not being applied to the subscriber. How
can we fix this?
One option is to open the post-snapshot file at the location
under “Run additional scripts”, fix the error, reinitialize the subscription and re-create the
snapshot. This might not be the best option depending on the size of your
snapshot and the time it takes to generate it.
The second option is to directly open the post-snapshot file
that was copied into the folder when the snapshot was created. By editing the
post-snapshot file in the folder specified in the “Put files in the default
folder” option, we are directly modifying the SQL that the distribution agent
is executing and failing on. If time is critical, you may want to remove all SQL
from the file and save it. Note: If you do this, you will have to manually apply the SQL to the subscriber. Once the error in the file either is fixed or the file is cleaned out, the distribution agent will open
the file and complete successfully. After that, all the
queue updates, inserts and deletes can flow from the publisher to the
subscriber.
Labels:
error,
replication,
snapshot,
SQL,
transactional
Tuesday, July 17, 2012
SQL Reporting Services (SSRS) 2008 R2 Administration Scripts
Below are a few SQL Reporting Services administration scripts that I've created to help me audit usage of the system.
1. Report Usage Count By User For The Previous 30 Days
2. Report Usage With Parameters, Row Count, Execution Time, Format and User Name
3. Report Location with Creation Date, Last Execution Date, and Usage Count
1. Report Usage Count By User For The Previous 30 Days
SELECT UserName
,COUNT(*) AS TimesExecutedFROM ReportServer.dbo.ExecutionLog3WHERE ItemPath LIKE '%<ReportName>%'
AND TimeStart > GETDATE() - 30GROUP BY UserNameORDER BY 2 DESC
2. Report Usage With Parameters, Row Count, Execution Time, Format and User Name
SELECT TimeStart
,Source
,[RowCount]
,Parameters
,UserName
,RequestType
,Format
,TimeDataRetrieval + TimeProcessing + TimeRendering [TimeInMilliseconds]FROM dbo.ExecutionLog3WHERE ItemPath LIKE '%<ReportName>%'
AND TimeStart BETWEEN '3/10/12' AND '6/11/12'ORDER BY 1 DESC3. Report Location with Creation Date, Last Execution Date, and Usage Count
SELECT Name
,CreationDate
,Path
,E.TimesExecuted
,E.LastExecutedFROM Catalog
INNER JOIN (SELECT ItemPath
,COUNT(*) AS TimesExecuted
,MAX(TimeStart) AS LastExecuted
FROM ExecutionLog3
GROUP BY ItemPath) E
ON CATALOG.PATH = E.ItemPathWHERE Path LIKE '/Reports%'
AND TYPE = 2ORDER BY 2 DESC
Labels:
ExecutionLog3,
SQL Reporting Services,
SSRS,
Usage
Monday, July 16, 2012
Subsystem 'CmdExec' could not be loaded (reason: The specified module could not be found)
After a recent server crash, we had the opprotunity to rebuild the SQL Server instance from the previous nights backups. After going through the various steps to restore the Master and MSDB databases, as well as change the location of the tempdb, resource and model databases, we thought everything was set.
Over the weekend, the server in question was set to backup user databases to a file share using SQLCMD. Upon starting the job, the SQL Agent returned the following error message: "Unable to start execution of step 1 (reason: The CMDEXEC subsystem failed to load [see the SQLAGENT.OUT file for details]; The job has been suspended). The step failed."
After looking throught the SQLAGENT.OUT file (which yielded the same error message), we took a look at the MSDB..SYSSUBSYSTEMS table. Looking in the subsystem_dll column, the issue presented itself.
SELECT subsystem
,subsystem_dll
FROM msdb..syssubsystems
subsystem subsystem_dll
CmdExec D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\binn\SQLCMDSS90.DLL
During the server rebuild, the SQL Server program files where installed under the C:\Program Files directory whereas on the crashed server installation, all the old binaries were installed under D:\Program Files. Since we restored the MSDB database from an old backup, those values overwrote the values from the new server install.
In order for the binaries to load, MSDB..SYSSUBSYSTEMS table had to be updated.
UPDATE msdb..syssubsystems
SET subsystem_dll = REPLACE(subsystem_dll,'D;\','C:\')
WHERE subsystem = 'CMDEXEC'
Once the subsystem_dll column has been updated to point to the C:\Program File directory, we restarted the SQL Agent service and checked the SQLAGENT.OUT file again. The error message was gone and the job completed successfully after we restarted it.
Over the weekend, the server in question was set to backup user databases to a file share using SQLCMD. Upon starting the job, the SQL Agent returned the following error message: "Unable to start execution of step 1 (reason: The CMDEXEC subsystem failed to load [see the SQLAGENT.OUT file for details]; The job has been suspended). The step failed."
After looking throught the SQLAGENT.OUT file (which yielded the same error message), we took a look at the MSDB..SYSSUBSYSTEMS table. Looking in the subsystem_dll column, the issue presented itself.
SELECT subsystem
,subsystem_dll
FROM msdb..syssubsystems
subsystem subsystem_dll
CmdExec D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\binn\SQLCMDSS90.DLL
During the server rebuild, the SQL Server program files where installed under the C:\Program Files directory whereas on the crashed server installation, all the old binaries were installed under D:\Program Files. Since we restored the MSDB database from an old backup, those values overwrote the values from the new server install.
In order for the binaries to load, MSDB..SYSSUBSYSTEMS table had to be updated.
UPDATE msdb..syssubsystems
SET subsystem_dll = REPLACE(subsystem_dll,'D;\','C:\')
WHERE subsystem = 'CMDEXEC'
Once the subsystem_dll column has been updated to point to the C:\Program File directory, we restarted the SQL Agent service and checked the SQLAGENT.OUT file again. The error message was gone and the job completed successfully after we restarted it.
Tuesday, May 22, 2012
SQL Reporting Services 2008 Execution Log History
In SQL Reporting Services 2008, you can set the Execution Log retention to keep more than the default 60 days by updating the ConfigurationInfo table inside the ReportServer database. Inside that table is a value labeled ExecutionLogDaysKept which can be updated to any value up to 2,147,483,647 , with 0 meaning that all history is kept indefinitely. You can update the value to keep 1 year's (365 days) worth of history with the script below.
UPDATE ConfigurationInfo
SET Value = '365'
WHERE Name = 'ExecutionLogDaysKept'
Friday, April 27, 2012
Dynamic Connection Strings in SSIS
If you need the ability to change connection strings in your SSIS packages without opening each one and hard coding a string, then dynamic connection strings are your answer. There are many different ways to do this, including Package Configurations and Parameters (2012), but here I’ll be explaining how to use variables to dynamically change the connection string using information stored in a flat file or database table that can be manipulated without opening the SSIS package. This make server renames / upgrades / moves much easier since the information only has to be changed in one place.
Starting out, we’ll need the source data. I’ve created a table with 2 columns, ConnectionName and ConnectionString along with some test data.
Next ,we will create a new variable scoped to the package called SourceConnectionString with a Data Type of String.
Now, select the Source connection in the Connection Manager and expand Expressions. This is where we’ll assign the SourceConnectionString variable to the ConnectionString of the Source connection via expressions.
Starting out, we’ll need the source data. I’ve created a table with 2 columns, ConnectionName and ConnectionString along with some test data.
CREATE TABLE ConnectionStrings
(ConnectionName VARCHAR(256)
,ConnectionString VARCHAR(256))
INSERT INTO ConnectionStrings
(ConnectionName
,ConnectionString)
VALUES ('<ConnectionName>',
'Data Source=<Server>;Initial Catalog=<Database>;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;'
)
Once
the data has been populated in the table, we can open up a new SSIS project in
the SQL Server Data Tools (2012) or BIDS (2008/2005) application and add a new
OLE DB Connection. At this point it doesn’t matter what connection string is
used since it will be overwritten at execution time, but for testing purposes
you will want to point it to your test system.
Next ,we will create a new variable scoped to the package called SourceConnectionString with a Data Type of String.
Now, select the Source connection in the Connection Manager and expand Expressions. This is where we’ll assign the SourceConnectionString variable to the ConnectionString of the Source connection via expressions.
Finally, we need to populate the SourceConnectionString variable
by querying the connection string table we setup in the first step. Once we
have the results from the query, we’ll assign the results to the variable,
which in turn assigns a connection string to the Source connection. This can be
accomplished by doing the following.
Under the Execute SQL Task Editor, the result set should be set to
Single Row and the SQL Statement should read “Select ConnectionString From
ConnectionStrings”
Next, under Result Set, assign Result Name 0 to the variable that
you created for the connection string.
Now that everything is set, the Source connection string value
will be filled with the value that you placed in the ConnectionStrings table.
Labels:
BIDS,
Connection String,
Dynamic,
sql server,
SSIS
Wednesday, March 21, 2012
Connect Item: Filter Tables and Views in SQL Server Import and Export Wizard
If you've ever used the SQL Server Import and Export Wizard inside SSMS on databases with hundreds of objects you know that it can be difficult to navigate the source tables and views grid looking for the object or objects you need. So to aleviate this I've created a Connect item to add the ability to filter objects when selecting the source tables and views. If you've had this problem or think this is a worthwhile suggestion, please vote it as important.
You can view the Connect item here:
https://connect.microsoft.com/SQLServer/feedback/details/732418/filter-tables-and-views-in-sql-server-import-and-export-wizard
Thanks,
Kevin
You can view the Connect item here:
https://connect.microsoft.com/SQLServer/feedback/details/732418/filter-tables-and-views-in-sql-server-import-and-export-wizard
Thanks,
Kevin
Labels:
connect,
microsoft,
sql server
Subscribe to:
Posts (Atom)






