~Ron
Archive for November, 2009
Windows 7 – Cannot Connect to Wireless Router
Published November 28, 2009 Security Leave a CommentTags: Networking, Security, Windows 7, WLAN
Using SSIS to Export a Fixed Width Flat File
Published November 27, 2009 RDBMS , SQL Server 17 CommentsTags: SQL Server 2005, SQL Server 2008, SSIS
After you create the database connection, go ahead and create the flat file destination connection. I used the c:\export directory and named my export file Export.txt, but anything will work. On the format drop down, select “Fixed width.”
Please ignore the “Column” sub-menu on the right for now. Select “Advanced” from the sub-menu on the right. Now we will create all of our columns. For this tutorial I created a mail merge type export using First Name, Last Name, Address, City, State and Zip. Add one column to handle the line feed/carriage return. Without this column the package output will concatenated into on one row.
On the Control Flow tab of the SSIS Package, add a data flow task. After adding the task, select the Data Flow tab. Add an OLE DB Source. On the OLE DB Connection Manager, the database connection we created earlier should already be selected. If it is not, select the connection we created at the beginning of the tutorial. The T-SQL used to select the data is below. Please note that there is no data formatting in the T-SQL, only the inclusion the column to handle the line feed/carriage return.
ANSI decimal character 10 is line feed, CHAR(10) in T-SQL, and ANSI decimal character 13 is a carriage return, CHAR(13) in T-SQL. Sometimes these characters are used in conjunction, depending on the format, but for our purposes we must use only one or the other.
SELECT
pc.LastName,
pc.FirstName,
pa.AddressLine1,
pa.City,
psp.StateProvinceCode,
pa.PostalCode,
CHAR(10) CRLF
FROM
Person.Contact pc
INNER JOIN HumanResources.Employee hre
ON pc.ContactID = hre.ContactID
INNER JOIN HumanResources.EmployeeAddress hrea
ON hre.EmployeeID = hrea.EmployeeID
INNER JOIN Person.Address pa
ON hrea.AddressID = pa.AddressID
INNER JOIN Person.StateProvince psp
ON pa.StateProvinceID = psp.StateProvinceID
WHERE
psp.CountryRegionCode = 'US' ;
One of the issues that you will face with any fixed width export are columns whose width is greater than the fixed width destination. We are going to handle this with a Data Conversion task. Be sure to give the converted column a friendly name, other than “Copy of ” and the column and set the length of the converted field to the same length of the destination fixed width column.
To make sure that the package succeeds if the width of the origin column is greater than the destination column, we will set the conversion to ignore all truncation errors. For these purposes it is important not to confuse width and length. A column with a data type of nchar(4) has a width of 4 but may have a length of 0 to 4. The data length may be less than or equal to destination, but if the width is greater it may prove problematic.
After adding the data conversions and error handling, let’s map the converted columns to our flat file destination columns.
That’s it. Run the package and you will see the fruits of your labor.
~Ron
UPDATE: The zipped solution can be downloaded from here. WordPress does not allow files of this type, so it is available via Dropbox.
I have Google Wave invitations to hand out. Please post in the comments if you want one.
*crossposted
Automatic redirect upon session timeout – using Javascript
Published November 24, 2009 .Net Leave a CommentTags: .Net, JQuery
We had a requirement that the logged in user should be automatically logged out after 5 minutes of inactivity. We tried the session_end event in global.asax but it didnt work as it should have. After thinking a bit me and bryan came up with a simple solution using Javascript which works really nice.
var wintimeout;
function SetWinTimeout() {
wintimeout = window.setTimeout("window.location.href='../weblogin/default.aspx';",300000); //after 5 mins i.e. 5 * 60 * 1000
}
$('body').click(function() {
window.clearTimeout(wintimeout); //when user clicks remove timeout and reset it
SetWinTimeout();
});
SetWinTimeout();
That is it. Just put the above code in document load ($) and it works like a charm. Just 5 mins away from keyboard and monitor would do a world of good.
Hope this helps.
Happy Programming!!!
Cheers,
Raja









