Wednesday, January 25, 2012

Kill Remote Session using QWINSTA and RWINSTA

If you need to terminal service to a remote windows server, but cant because no sessions are available, you can use QWINSTA and RWINSTA to query then kill offending sessions so then you can get to the server.


First, use QWINSTA to query the sessions:
From a command prompt enter:
qwinsta /server:servername
Example:



In the above example I have shown “nameofserver” instead of the actual server name.
Note the ID of the session that you want to kill. In this case, we will kill session ID 2 (pdouglas)

To kill the session, use RWINSTA:
From the command prompt enter:
rwinsta ID /server:servername
Example:

Tuesday, January 10, 2012

SQL: Hints: Find all tables that contain a given column

This falls under the category of SQL Hints. These are things I need to do occassionally, and normallly forget the exact sytax required, so I will place it here in case I need it in the future.

If you have a large database with many tables, you sometimes may need to quickly find out all the tables that contain a certain column.  The below query will list out all the tables that contain the given column name (in this example 'user_name'). 

DECLARE @String varchar(100)
SET @String = 'user_name'
SELECT
DISTINCT
o.name as Table_Name, c.name as Column_Name, c.is_nullable
FROM sys.columns c
INNER JOIN sys.objects o
ON c.object_id = o.object_id
WHERE c.name = @String
ORDER BY o.name

Output will be like this:
Table_NameColumn_Nameis_nullable
usersuser_name0
ordersuser_name1
logsuser_name1

Monday, January 9, 2012

Agile: Agile/Scrum Methods Blog

I found a good blog on Agile methods by Kelly Waters.  It has many good articles on agile and scrum.
Here are the first two I have read:

http://www.allaboutagile.com/category/10-key-principles-of-agile/ -- this is an easy read that discusses key principles of agile:
10 Key Principles of Agile Development
1 - Active User Involvement Is Imperative
2 - Agile Teams Must Be Empowered
3 - Time Waits For No Man
4 - Agile Requirements Are Barely Sufficient
5 - How Do You Eat An Elephant?
6 - Fast But Not So Furious
7 - Done Means DONE!
8 - Enough Is Enough
9 - Agile Testing Is Not For Dummies
10 - No Place For Snipers

http://www.allaboutagile.com/how-to-implement-scrum-in-10-easy-steps/  -- this article discusses the scrum process step-by-step.  It pretty much mimicks what we learned in our scrum training:
How To Implement Scrum in 10 Easy Steps
1 - Get Your Backlog In Order
2 - How To Estimate Your Product Backlog
3 - Sprint Planning (Requirements)
4 - Sprint Planning (Tasks)
5 - Create a Collaborative Workspace
6 - Sprint!
7 - Stand Up and Be Counted!
8 - Track Progress / Daily Burndown Chart
9 - Finish When You Said You Would
10 - Review, Reflect, Repeat

I encourage you to read these!

Friday, January 6, 2012

SSIS: Calling an SSIS package from a batch file

I typically execute my SSIS packages on an app server using the dtexec utility and a batch file.  This gives several advantages:
  1. It allows me to execute the package from an automated scheduler program (we use autosys)
  2. Allows for a config file in a different location than when the package was created
  3. Outputs a log file in a specified location with the date in the file name
Here is an example batch file that  I use:
@echo off

FOR /F "tokens=2-4 delims=/ " %%i IN ('date /t') DO SET DATE=%%i-%%j-%%k
dtexec /FILE E:\SSIS_PACKAGES\PSFeedSSIS\PSFeedSSIS.dtsx /DECRYPT password /ConfigFile E:\SSIS_PACKAGES\PSFeedSSIS\PSStageConfig.dtsConfig /CHECKPOINTING OFF > E:\SSIS_PACKAGES\PSFeedSSIS\Logs\%DATE%PSStageLog.txt
if ERRORLEVEL 0 SET ERRORLEV=0
if ERRORLEVEL 1 SET ERRORLEV=1
echo ERRORLEVEL = %ERRORLEV%
exit /B %ERRORLEV%
echo PS Stage Complete

Some pieces of the batch file:
  • the /FILE parameter gives the name of the package itself
  • /DECRYPT gives the package password if set
  • /ConfigFile gives the location of the config file
  • /CHECKPOINTING OFF  checkpointing will not be used during execution
  • the redirect > puts the output log file to the specified location.  The logfile name will have the date in the filename (%DATE%) variable
  • The last part of the batch file is setting the Error level then propagating that error code out to the exit code of the batch file.  This was necessary in our case so that the autosys scheduler program would recognize a failure condition.
Click Here for more information on the dtexec utility.