CFMX and SQL Server Data Transformation Services (Part Two of Two) |
|---|
| *Use SQL Query Analyzer to run SQL Scripts in
the following order. *Note: sp_displayoaerrorinfo.sql, spDisplayPKGErrors.sql, spExecuteDTS.sql credit goes to Pengoworks.com |
| SQL Server |
| sp_displayoaerrorinfo.sql [1] |
| CREATE PROC sp_displayoaerrorinfo @object as int AS DECLARE @hr int PRINT 'OLE Automation Error Information' EXEC @hr = sp_OAGetErrorInfo @object, @source OUT, @description OUT GO |
| spDisplayPKGErrors.sql [2] |
| -- display errors from spExecuteDTS execution CREATE PROC spDisplayPKGErrors @oPkg As integer AS SET NOCOUNT ON DECLARE @StepCount int DECLARE @StepName varchar(255) IF OBJECT_ID('tempdb..#PkgResult') IS NOT NULL CREATE TABLE #PkgResult SELECT @oPkgResult = 0 EXEC @hr = sp_OAGetProperty @oPkg, 'Steps', @Steps OUTPUT EXEC @hr = sp_OAGetProperty @Steps, 'Count', @StepCount OUTPUT WHILE @StepCount > 0 EXEC @hr = sp_OAGetProperty @Step, 'ExecutionResult', @StepResult OUTPUT
EXEC @hr = sp_OAGetProperty @Step, 'Description', @StepDescription OUTPUT INSERT #PkgResult VALUES(@StepName, @StepDescription, @StepResult) SELECT @StepCount = @StepCount - 1 SELECT * FROM #PkgResult IF @oPkgResult > 0 GO |
| spExecuteDTS.sql [3] |
| CREATE PROC spExecuteDTS @Server varchar(255), @PkgName varchar(255), -- Package Name (Defaults to most recent version) @ServerPWD varchar(255) = Null, -- Server Password if using SQL Security to load Package (UID is SUSER_NAME()) @IntSecurity bit = 0, -- 0 = SQL Server Security, 1 = Integrated Security @PkgPWD varchar(255) = '' -- Package Password AS SET NOCOUNT ON -- Create a Pkg Object -- Evaluate Security and Build LoadFromSQLServer Statement EXEC @hr = sp_OAMethod @oPKG, @Cmd, NULL IF @hr <> 0 -- Execute Pkg -- Check Pkg Errors -- Unitialize the Pkg -- Clean Up RETURN @ret GO |
| Tracking.sql [4] |
| CREATE TABLE Tracking( browser varchar(50) NULL, [date] datetime NULL ); |
| spGetStats.sql [5] |
| CREATE PROC spGetStats
AS
INSERT INTO #tempTracking SELECT SUM(visitorCount) as visitorSum, browser DROP TABLE #tempTracking GO |
| SQL Server DTS Package |
| Step 1: |
| Open SQL Server Enterprise Manager, Microsoft SQL Servers > SQL Server Group > (Server name) Server > Data Transformation Services then right-click "Local Packages" and select "New Package". When your design sheet window pops up, select "Package" menu item and the select "Save As", then type "cfmxDTS" in the Package Name field and click OK. |
| Step 2: |
| With your package design sheet still open, click the |
| Step 3: |
| Again with your package design sheet still open, click the
Your design sheet should now look like this...
|
| Step 4: |
| Again with your package design sheet still open, again...
Click the Transform Data Task Your design sheet should now look like this. Make sure your arrow is pointing from your source to your destination.. Next, double click the transform data task (not the icon, the line with the arrow) and type "[1-1] Transform tracking data" in the description field, click the Destination tab and make sure you select the "Tracking" table from the table name select list, click OK. Now we are ready to test it... Go to http://localhost/cfmxDTS and click the submit button to populate the text file with 1000 records, or click it 5 or 6 or 10 times just to see how slow it actualy appends data to the file. Next click the "DTS Package" link on the left hand navigation and click the submit button to run the DTS Package and then you will see the benefits of using a tool like DTS to move the data from one source to another. |
So that's all there is to it... If you have any questions feel free to contact me here.. Just click on the image and a contact form will pop up.. And yes I do look like that. Until next time... (Probably Adjacency Lists) Enjoy, Tedd |