Thursday, November 6, 2014
PdfSharp Chinese Encoding
Recently I started to use PdfSharp open source project, this is a great tool and its document rendering speed is great with small-medium sized pdf docs.
Anyway, in our program's pdf export function, it has a requirement to be able to cater for different languages such as CJK (Chinese, Japanese, Korean), etc. I got some hints from pdfsharp's forum, here's what's going to solve the issue:
Private Sub DefineStyles()
' Get the predefined style Normal.
Dim style As Style = Me.document.Styles("Normal")
' Because all styles are derived from Normal, the next line changes the
' font of the whole document. Or, more exactly, it changes the font of
' all styles and paragraphs that do not redefine the font.
style.Font.Name = "Arial Unicode MS" 'This font will make Chinese characters display
' Create a new style called Table based on style Normal
style = Me.document.Styles.AddStyle("Table", "Normal")
style.Font.Name = "Arial Unicode MS"
style.Font.Size = 10 'Default font
End Sub
Thursday, February 20, 2014
Don't save any sensitive data into your MS Office products
Just don't do it, it takes a person less 1 minute to search on google and crack whatever password that you put on to 'protect' your file.
E.g. http://uknowit.uwgb.edu/page.php?id=28850
there are quite a few programs out there to crack your MS access password, so use SQL server if you can, access is really for fun.
E.g. http://uknowit.uwgb.edu/page.php?id=28850
there are quite a few programs out there to crack your MS access password, so use SQL server if you can, access is really for fun.
Tuesday, October 15, 2013
Random values in Select Query to hide information
There are situations when manager or BA want you to hide certain information in a report, there are a lot of programming ways to achieve this, for laziness it is also doable in SQL.
E.g. I have a list of sensitive customer name and their sales figure, I would like to show the other party how many sales I made, however hiding all the names.
the idea came to my mind is, using a string 'Customer' and a random number from 1-10 combine to get a random name such as 'Customer5', etc.
syntax:
'Customer' + CAST((CAST(RAND(CHECKSUM(NEWID())) * 10 as INT) + 1) as varchar(2))
RAND(Checksum(NEWID()))
Above provides a random number between 0 - 1, use it as root times 10 to get a random number between 1- 10. hence end up having 'Customer1' - 'Customer10' in the selection list.
E.g. I have a list of sensitive customer name and their sales figure, I would like to show the other party how many sales I made, however hiding all the names.
the idea came to my mind is, using a string 'Customer' and a random number from 1-10 combine to get a random name such as 'Customer5', etc.
syntax:
'Customer' + CAST((CAST(RAND(CHECKSUM(NEWID())) * 10 as INT) + 1) as varchar(2))
RAND(Checksum(NEWID()))
Above provides a random number between 0 - 1, use it as root times 10 to get a random number between 1- 10. hence end up having 'Customer1' - 'Customer10' in the selection list.
Wednesday, July 17, 2013
Unlock System administrator account in SQL 2008 R2
If for some reason the system admin account got locked out of SQL server, you may take the following steps to unlock it.
Step 1 Add a new user using current ‘Windows Login user name’, e.g. PBTECH\Michael , then Stop SQL server
Step 2 Change the server into single user mode, by add “;-m” at the end of path under SQL server property window advanced tab
Step 3: Save & restart, login to SSMS with windows authentication
Step 4: Give the new user added in step 1 System admin permission by executing :
sp_addsrvrolemember [domain\username],'sysadmin'
Step 5: Under security- login find the locked user, reset password and untick the lock, save and close.
Step 5: reverse step of step2, change SQL server back to multi user mode
The SA should be unlocked.
Step 1 Add a new user using current ‘Windows Login user name’, e.g. PBTECH\Michael , then Stop SQL server
Step 2 Change the server into single user mode, by add “;-m” at the end of path under SQL server property window advanced tab
Step 3: Save & restart, login to SSMS with windows authentication
Step 4: Give the new user added in step 1 System admin permission by executing :
sp_addsrvrolemember [domain\username],'sysadmin'
Step 5: Under security- login find the locked user, reset password and untick the lock, save and close.
Step 5: reverse step of step2, change SQL server back to multi user mode
The SA should be unlocked.
Thursday, April 18, 2013
To Make your window form show as topmost window in VB.Net
In VB6 we used to use API function like :
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
the equivalent function in .Net is something like:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As b ShowWindowCommands) As Boolean
End Function
To make your window to topmost of your screen, there're a few simple steps to take:
Dim ProcessProperties As New ProcessStartInfo
ProcessProperties.FileName = "test.exe"
ProcessProperties.Arguments = ""
Dim myProcess As Process = Process.Start(ProcessProperties)
Return myProcess.ID
End Function
'SET API And variables
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
End Function
Private Const SWP_NOSIZE As Integer = &H1
Private Const SWP_NOMOVE As Integer = &H2
Private Shared ReadOnly HWND_TOPMOST As New IntPtr(-1)
Private Shared ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
'Set Window Pos to top most
Public Shared Sub SwitchToProcess(ByVal PID As Integer)
Dim hWnd As Integer
hWnd = CType(System.Diagnostics.Process.GetProcessById(PID).MainWindowHandle, Integer)
'ShowWindow(hWnd, SW_MAX)
'ShowWindow(hWnd, ShowWindowCommands.ShowNoActivate)
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
the equivalent function in .Net is something like:
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function ShowWindow(ByVal hwnd As IntPtr, ByVal nCmdShow As b ShowWindowCommands) As Boolean
End Function
To make your window to topmost of your screen, there're a few simple steps to take:
- Get your process ID when you call the program
Dim ProcessProperties As New ProcessStartInfo
ProcessProperties.FileName = "test.exe"
ProcessProperties.Arguments = ""
Dim myProcess As Process = Process.Start(ProcessProperties)
Return myProcess.ID
End Function
- Use the ProcessID to get window's Handle and set it to topmost
'SET API And variables
<DllImport("user32.dll", CharSet:=CharSet.Auto, SetLastError:=True)> _
Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As Integer) As Boolean
End Function
Private Const SWP_NOSIZE As Integer = &H1
Private Const SWP_NOMOVE As Integer = &H2
Private Shared ReadOnly HWND_TOPMOST As New IntPtr(-1)
Private Shared ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
'Set Window Pos to top most
Public Shared Sub SwitchToProcess(ByVal PID As Integer)
Dim hWnd As Integer
hWnd = CType(System.Diagnostics.Process.GetProcessById(PID).MainWindowHandle, Integer)
'ShowWindow(hWnd, SW_MAX)
'ShowWindow(hWnd, ShowWindowCommands.ShowNoActivate)
SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
End Sub
Wednesday, February 6, 2013
Excel 2010 Querying(parameterised) SQL
Simple reports for end user may require you to run some query on an excel spreasheet, so that end user can refresh and get live data as they want and when they want.
Couple ways to do:
Create a View in SQL server, save it, then Open up Excel 2010
Couple ways to do:
Create a View in SQL server, save it, then Open up Excel 2010
Choose 'From Microsoft Query' (You can, if you wish, to choose SQL server, what i noticed was you cannot change your query or put dynamic parameters if you choose that)
Point to the database server of your choice, Click 'Ok' then Click Cancel, it'll pop up asking whether you want to enter query editing window, click 'Yes'.
Then choose the table you wish to display in SQL Query edit window, you can then add criteria and modify the query and look of the output. even add parameters.
After you done with your query editing, click 'File --> Return Data to Excel' to go back to Excel main window.(Note: if you added parameters in your query, you'll need to fresh the connection to be able to set the parameter look up value, i.e. a cell or range of cells.)
User will be able to simply change the parameter to get the data refreshed. Easy as~
Monday, January 14, 2013
Auto Refreshing Excel data connection without open up excel
Ever wanted to get a bunch of pivot table data on excel files refreshed without the need of opening the file at all?
Here's a solution,
download the zip and extract. To use, just create a batch file and execute the .exe file on command line.
http://search.cpan.org/~ctbrown/Win32-Excel-Refresh-0.02/Refresh.pm
Here's a solution,
download the zip and extract. To use, just create a batch file and execute the .exe file on command line.
http://search.cpan.org/~ctbrown/Win32-Excel-Refresh-0.02/Refresh.pm
Import Excel into SQL 2008 64 bit
Last couple days, I was working on a solution to import some excel file into SQL and then generate report from the server.
There're a lot of ways to import an excel file, I tried a few approaches, unfortunately due to lack of permission to muck around with server settings in the company, I was unable to proceed with most of these approaches.
Approach 1 : (ISSUE: 32 bit office installed, 64bit SQL installed)
I did run step 2&3 on my local machine (XP sp3, 32bit SQL 2008 R2), work like a charm.
Possible issues:
you may come across:
This will fix it :
Also this error is common:
Fixes:
-------------------------------SEPERATOR ------------------------------------------------------------
Approach 2: LINKED Server
Same issue with the first approach, 32 bit office and 64 bit SQL. on all 32 bit servers, everything goes smoothly, where as 64 bit SQL will have errors and not be able to proceed.
There're a lot of ways to import an excel file, I tried a few approaches, unfortunately due to lack of permission to muck around with server settings in the company, I was unable to proceed with most of these approaches.
Approach 1 : (ISSUE: 32 bit office installed, 64bit SQL installed)
Step 1. Install 64-bit Microsoft.ACE.OLEDB.12.0 driver (Failed on this one, Don't have server admin rights to install 64 bit version drivers.)
Step 2. Configure ACE OLE DB properties
EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1 GO EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1 GO
Step 3. Configure linked server using Microsoft.ACE.OLEDB.12.0 provider
SELECT * INTO #ExcelTemp FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=V:\database\Export\Service KPI Report 2013.xls','select * from [2013$]')
I did run step 2&3 on my local machine (XP sp3, 32bit SQL 2008 R2), work like a charm.
Possible issues:
you may come across:
Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure. For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.
This will fix it :
sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO
Also this error is common:
Msg 7399, Level 16, State 1, Line 1The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. Access denied.Msg 7350, Level 16, State 2, Line 1Cannot get the column information from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
Fixes:
USE [master]GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'NestedQueries', 1GOEXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'NonTransactedUpdates', 1GO
-------------------------------SEPERATOR ------------------------------------------------------------
Approach 2: LINKED Server
Same issue with the first approach, 32 bit office and 64 bit SQL. on all 32 bit servers, everything goes smoothly, where as 64 bit SQL will have errors and not be able to proceed.
EXEC sp_addlinkedserver @server = 'ExcelServer', @srvproduct = 'Excel', @provider = 'Microsoft.ACE.OLEDB.12.0', @datasrc = 'C:\Test\test.xlsx', @provstr = 'Excel 12.0;IMEX=1;HDR=YES;'
-------------------------------SEPERATOR ------------------------------------------------------------
Approach 3: SSIS
Easy enough, end up doing this.
Tuesday, December 11, 2012
Terminating Database Restoring process
You may occasionally want to terminate an ongoing restoration process of your database backup.
In MS SQL 2008 R2, I don't find there's an easy way of doing so, currently I don't believe there's a cancel selection or w/e for this kind of purpose. So in this case, we'll have to do it manually and brutally.
To start with:
Stop your SQL Server Agent service
Then stop SQL Server Service.
Delete/rename the .Bak file you were using to restore your database.
Delete the log files or db files has been created from the restore
Start both services.
Relog into SSMS and check, you probably will still see 'DB(Restoring.....)'
To get rid of this, do a manual restore from Wizard, using any .bak file you want name it to 'DB'.
Once done, this should go away.
In MS SQL 2008 R2, I don't find there's an easy way of doing so, currently I don't believe there's a cancel selection or w/e for this kind of purpose. So in this case, we'll have to do it manually and brutally.
To start with:
Stop your SQL Server Agent service
Then stop SQL Server Service.
Delete/rename the .Bak file you were using to restore your database.
Delete the log files or db files has been created from the restore
Start both services.
Relog into SSMS and check, you probably will still see 'DB(Restoring.....)'
To get rid of this, do a manual restore from Wizard, using any .bak file you want name it to 'DB'.
Once done, this should go away.
Wednesday, December 5, 2012
T-SQL MERGE (Ver2)
A reminder,
Merge ...
WHEN Matched And (Search condition) THEN
Update Set ****
Update can only be use once in Merge statement, so if there're multiple conditions, you will need to specify all of them in (Search Condition).
WHEN Not Matched cannot use Update, Only Delete/Insert can be used.
Example:
To update Product RRP with source table, conditions: update using source if source RRP less than current RRP, or if current RRP is 0 but source isn't.
Merge dbo.Products ip
USING (Select vendor_code, min(RRP) as Rp FROM zab_Supplierpricelist Where RRP > 0 and vendor_code > ''
Group by vendor_code) as ms
ON ip.zextpartno = ms.vendor_code AND ip.status in ('A','R') WHEN Matched and ((ip.ZRRP > ms.Rp) OR (ip.ZRRP =0 AND ms.RP > 0)) THEN
UPDATE SET ip.ZRRP = ms.RP;
Merge ...
WHEN Matched And (Search condition) THEN
Update Set ****
Update can only be use once in Merge statement, so if there're multiple conditions, you will need to specify all of them in (Search Condition).
WHEN Not Matched cannot use Update, Only Delete/Insert can be used.
Example:
To update Product RRP with source table, conditions: update using source if source RRP less than current RRP, or if current RRP is 0 but source isn't.
Merge dbo.Products ip
USING (Select vendor_code, min(RRP) as Rp FROM zab_Supplierpricelist Where RRP > 0 and vendor_code > ''
Group by vendor_code) as ms
ON ip.zextpartno = ms.vendor_code AND ip.status in ('A','R') WHEN Matched and ((ip.ZRRP > ms.Rp) OR (ip.ZRRP =0 AND ms.RP > 0)) THEN
UPDATE SET ip.ZRRP = ms.RP;
Sunday, August 19, 2012
Background worker and progress bars tutorial
I have recently knocked up a simple tutorial of the use of background worker and progress bars when there's a need of use such. General purpose is to make a more user friendly interface, as sometimes the program will hang if the processing time takes more than a few sec. ( some users will then think the program is dead and may force shut down the program.)
ppt link:
https://sites.google.com/site/maimailearns2vb/first/Back%20Ground%20Worker%20n%20Progress%20Bars.pptx?attredirects=0&d=1
ppt link:
https://sites.google.com/site/maimailearns2vb/first/Back%20Ground%20Worker%20n%20Progress%20Bars.pptx?attredirects=0&d=1
Monday, August 13, 2012
Windows Server 2008 R2 Printer Log Enabling
'Start' -- 'Printers & faxes' -- right click select 'Server Properties' -- 'Advanced' -- Check 'Log spooler information events' --- Restart Machine.
To Check Log
Server Manager --> Event Viewer --> Applications and Service Logs --> Microsoft --> Windows --> Print Service
Sunday, July 29, 2012
Race Condition Errors when deleting copying network file
I have encountered a strange issue since last Friday, which never happened before on our servers. I have a program sending out reports to customers/suppliers on daily basis, one of the functions are sending out the file with same name, say "Your List".
Everything goes perfectly smooth until last Friday, i saw some errors: Error creating csv/xls file. I then went thru the program to see if i could replicate the issue, unfortunately it runs all good when I tried the same functions on my own. So I added a log to see what's the actual error was, turns out to be : Cannot copy the file to "Your List", it's been accessed by another user. Well since it runs overnight, and no one is using the file at all times, I can only assume this is caused by trying to copying the file before the Deleting process has finished.
Well this does happen and a lot on network file copying/deleting.
I tried to give a delay between deleting and copying, well it does help a little, but it's not always a good idea as error will still come at some stage.
In my case, I changed the file name to add either customer name or supplier name, which make those files all different, and fixed the problem. Although it'll be better to know an alternative way of solving the issue without changing the name.
Thursday, June 7, 2012
Merge IN SQL 2008
I recently came across a scenario where i need to run a loop to update/insert multiple records into a existing table. There's a very easy and clean way of doing so in SQL 2008, with the 'Merge' method, it is achievable in just a couple lines of codes.
What i did was:
Step1 : Create a temp table
CREATE TABLE #Stock -- source
(
ProductCode Varchar(50) NOT NULL PRIMARY KEY,
Quantity INT NOT NULL,
CONSTRAINT Quantity_Default_2 DEFAULT 0
);
--Insert Record into the temp table for later update merge
Insert INTO #Stock(ProductCode, Quantity)
Select ProductCode, Quantity FROM dbo.Products WHERE Category = 'blahblah'
;
Step2: Merge temp table with target table
--Merge with target table
Merge [integration_products] ip
USING #Stock ms
ON ip.ProductCode = ms.ProductCode
WHEN Matched THEN -- Matching Case DO update
UPDATE
SET ip.QtyOnhand = ms.Quantity + ip.QtyOnhand
WHEN Not Matched By Target THEN --Insert
INSERT ([ProductCode],[Status],[Category],[MinQuantity],[MaxQuantity],[CustOrders],[CustBackOrders],[SuppOrders],[QtyOnHand])
VALUES (ms.ProductCode, ms.[Status], ms.[Category], 0,0,0,0,0,ms.Quantity);
What i did was:
Step1 : Create a temp table
CREATE TABLE #Stock -- source
(
ProductCode Varchar(50) NOT NULL PRIMARY KEY,
Quantity INT NOT NULL,
CONSTRAINT Quantity_Default_2 DEFAULT 0
);
--Insert Record into the temp table for later update merge
Insert INTO #Stock(ProductCode, Quantity)
Select ProductCode, Quantity FROM dbo.Products WHERE Category = 'blahblah'
;
Step2: Merge temp table with target table
--Merge with target table
Merge [integration_products] ip
USING #Stock ms
ON ip.ProductCode = ms.ProductCode
WHEN Matched THEN -- Matching Case DO update
UPDATE
SET ip.QtyOnhand = ms.Quantity + ip.QtyOnhand
WHEN Not Matched By Target THEN --Insert
INSERT ([ProductCode],[Status],[Category],[MinQuantity],[MaxQuantity],[CustOrders],[CustBackOrders],[SuppOrders],[QtyOnHand])
VALUES (ms.ProductCode, ms.[Status], ms.[Category], 0,0,0,0,0,ms.Quantity);
Tuesday, April 17, 2012
SSIS Excel column datatype problem Ver2.0:
I have come across another similar situation today when using one of the excel file received couple days back. turns out the 'quantity' column has numbers and strings like (5,10, "100+"). Problem with this is during the validation of the package, "100+" are discarded by the package and returned to me as "Null" values.
In this case unfortunately only thing I could do is parse the whole sheet in as one column and then write script to differentiate columns.
I have come across another similar situation today when using one of the excel file received couple days back. turns out the 'quantity' column has numbers and strings like (5,10, "100+"). Problem with this is during the validation of the package, "100+" are discarded by the package and returned to me as "Null" values.
In this case unfortunately only thing I could do is parse the whole sheet in as one column and then write script to differentiate columns.
Wednesday, November 9, 2011
Recently came across a problem with nicely formatted excel file(with all pictures, bolded colorful text headings, etc), I wanted to import the important data into our database using SSIS, however with all these junk info at the start. SSIS didn't behave as I wanted, instead of importing all the prices figures it imported all null values instead.
I did some search on the net, found that SSIS was defaulted using first 8 rows in an Excel file to determine the datatype, which in my case, all first 8 lines were blank. So problem found, but to fix it, how?
There are couple solutions to this issue:
1. Simple and maybe the most easier way to do it. Change the 'Openrowset' Property under Excel Data Source's Properties, from 'Sheet1$', to Sheet1$A1:G1000. basically manually set the range you want, which handles this problem perfectly.
2. Use Script component to code for filtering, Read the file in as a whole inside script component, then looping through each individual rows to filter which to keep.
3. Manually change the property field type of source Excel file column, in my case, set "price " column from 'number' to 'text'
4. MSDN suggests there's an registry key you may change to determine how many rows to check by SSIS before determination of the column type. Named: TypeGuessRows under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Excel.
Wednesday, June 8, 2011
Return Maximum Number in an array
I was asked to write a function to return the maximum number in a given array once in a job interview when I have little programming knowledge. I didn't make the move there but after I studied a bit, I found it is actually a very easy task. There are more than one way of doing this, I'll just illustrate two here:
Solution 1:
Private Function GetMaxNumber() As Integer
Dim ages() As Integer = {12, 53, 14, 26, 35, 24, 39, 45}
'set the age of the first element for comparison
Dim oldest As Integer = ages(0)
'now loop through all the ages in the array
For i As Integer = 0 To UBound(ages) - 1
'check if the current age is greater than the highest age
'that has been found so far
If oldest < ages(i) Then
'store the value of the element in the array
oldest = ages(i)
End If
Next
Return oldest
End Function
Solution 2:
Private Function GetMax() As Integer
Dim nums() As Integer = {12, 53, 14, 26, 35, 24, 39, 45}
Dim largest = (From num In nums Select num).Max
Return largest
End Function
Using LINQ in Visual studio 2008 you can tell it is much easier to do this
Solution 1:
Private Function GetMaxNumber() As Integer
Dim ages() As Integer = {12, 53, 14, 26, 35, 24, 39, 45}
'set the age of the first element for comparison
Dim oldest As Integer = ages(0)
'now loop through all the ages in the array
For i As Integer = 0 To UBound(ages) - 1
'check if the current age is greater than the highest age
'that has been found so far
If oldest < ages(i) Then
'store the value of the element in the array
oldest = ages(i)
End If
Next
Return oldest
End Function
Solution 2:
Private Function GetMax() As Integer
Dim nums() As Integer = {12, 53, 14, 26, 35, 24, 39, 45}
Dim largest = (From num In nums Select num).Max
Return largest
End Function
Using LINQ in Visual studio 2008 you can tell it is much easier to do this
Wednesday, May 25, 2011
SSIS Package error handling
Sometimes when you running a SSIS package with hundreds of dataflow tasks you simply don't want to have frustrations of one error at pre-validation ruins the whole package, as it might just be a tiny error but cost you hours of debugging and more importantly, may even slow down the business process.
Recently I've come across similar problems with one of my packages, and i digged a little which I found a few approaches that could cater such issue.
Approach 1: my case, I have dozens of dataflow tasks running parallel and I want to allow some file changes and format changes to cause error but package still runs and I could get back to the error later on after I receive the error Email I set for each individual task.
To do this is really simple, just change the main control flow's property "maximumerrorcount" to whatever size you like but 1. If you wish, you can also set individual dataflow task's max error count number as well. but all these must based on that you have a very good understanding of what your package is doing and what sort of error you're expecting. If you're not sure of the errors, then you should also add some error handling in event handlers' of tasks.
Approach 2: A more sophisticated solution for this kind of issue is to write a script task to do the file validations yourself before the package does, and set variables whether the following child task should run or not based on your script task result. here's a link of showing an example: http://dichotic.wordpress.com/2006/11/01/ssis-test-for-data-files-existence/
Personally I found first one is really simple, but as I'm aware of, if error handling isn't good enough you might end up spending more time when weird error occurs.
Recently I've come across similar problems with one of my packages, and i digged a little which I found a few approaches that could cater such issue.
Approach 1: my case, I have dozens of dataflow tasks running parallel and I want to allow some file changes and format changes to cause error but package still runs and I could get back to the error later on after I receive the error Email I set for each individual task.
To do this is really simple, just change the main control flow's property "maximumerrorcount" to whatever size you like but 1. If you wish, you can also set individual dataflow task's max error count number as well. but all these must based on that you have a very good understanding of what your package is doing and what sort of error you're expecting. If you're not sure of the errors, then you should also add some error handling in event handlers' of tasks.
Approach 2: A more sophisticated solution for this kind of issue is to write a script task to do the file validations yourself before the package does, and set variables whether the following child task should run or not based on your script task result. here's a link of showing an example: http://dichotic.wordpress.com/2006/11/01/ssis-test-for-data-files-existence/
Personally I found first one is really simple, but as I'm aware of, if error handling isn't good enough you might end up spending more time when weird error occurs.
Thursday, May 19, 2011
“Cannot generate SSPI context” error message
I ran into this problem when i'm doing testings on my local machine, after a little bit search i found out the actual problem was I set my local time to 2 months ago and there has been a mismatch of time clock between server and client, therefore this error pop up.
so after changing my local time back to current time, it's all good again.
so after changing my local time back to current time, it's all good again.
Wednesday, May 11, 2011
Outlook blocked access to the following potentially unsafe attachments
Sometimes you may receive this message when receiving email from others with a file attached it.
To deal with it if changing security settings of your exchange server admin isn't an option, there are a few steps to get rid of this message:
To deal with it if changing security settings of your exchange server admin isn't an option, there are a few steps to get rid of this message:
- Exit Outlook if it is running.
- Click Start, and then click Run. Copy and paste (or type) the following command in theOpen box, and then press ENTER:regedit
- Verify that the following registry key for your version of Outlook exists.
Microsoft Office Outlook 2010HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\SecurityMicrosoft Office Outlook 2007HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\SecurityMicrosoft Office Outlook 2003HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\SecurityMicrosoft Outlook 2002HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\SecurityMicrosoft Outlook 2000HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Outlook\SecurityIf the registry key exists, go to step 5.
If the registry key does not exist, follow these steps to create it:- Locate, and then click the following registry key:HKEY_CURRENT_USER\Software\Microsoft
- Under Edit, click New, and then click Key.
- Type Office, and then press ENTER.
- Under Edit, click New, and then click Key.
- For Outlook 2010, type 14.0, and then press ENTER.
For Outlook 2007, type 12.0, and then press ENTER.
For Outlook 2003, type 11.0, and then press ENTER.
For Outlook 2002, type 10.0, and then press ENTER.
For Outlook 2000, type 9.0, and then press ENTER. - Under Edit, click New, and then click Key.
- Type Outlook, and then press ENTER.
- Under Edit, click New, and then click Key.
- Type Security, and then press ENTER.
- Locate, and then click the following registry key:
- Under Edit, click New, and then click String Value.
- Copy and paste (or type) the following name for the new value:Level1Remove
- Press ENTER.
- Right-click the new string value name, and then click Modify.
- Type the file name extension of the file type that you want to open in Outlook. For example:.exeTo specify multiple file types, use the following format:.exe;.com
- Click OK.
- Exit Registry Editor.
- Restart your computer.
the source link for this solution is :http://support.microsoft.com/kb/829982
Subscribe to:
Posts (Atom)







