How to get .pst Outlook File into SQL 2000 using DTS - My Solution -
02-19-2004
, 09:01 AM
With appropriate acknowledgments to Allan Mitchell and Justin Engleman
who have contributed to various other postings.
My Solution is a bit clugy and a 2 part one
1st we export all the PST to individual CSVs saving as username.csv
'************************************************* *********************
' Visual Basic ActiveX Script 'I got this from Allan Engleman's
example and modified it as much
' as I could understand
'************************************************* ***********************
Function Main()
Dim oConn, sFilename, cnOwner
cnOwner = inputbox("Who is the PST Owner")
sFilename = cnOwner
sFilename = sFilename & ".csv"
DTSGlobalVariables("UserName").Value = cnOwner
Set oConn = DTSGlobalVariables.Parent.Connections("Connection 1")
oConn.DataSource = sFilename
Set oConn = Nothing
'msgbox DTSGlobalVariables("UserName").Value
Main = DTSTaskExecResult_Success
End Function
then using EM I have a DTS package that prompts the user to enter
username
of csv to import, it imports it into a temptable, then runs a ActiveX
SQL
Statement
'First I generate an AutoNumber and append it to the TempContact table
imported
select
IDENTITY(smallint, 1, 1) AS AutoNum,
*
into tbl_stagecontact
from tbl_TempContact ' tbl_TempContact is a the table imported from
the CSV that has ALL Contact Fields
insert into tbl_newTempContact
select ? as cnOwner, * From tbl_stagecontact 'This is where I pass
the GlobalVariable cnOwner from the first ActiveX script
GO
drop table tbl_stagecontact 'House Keeping
GO
delete from tbl_tempContact 'More HouseKeeping
that adds the username as ContactOwner to the TempTable for
parsing into a future WebApplication using Contact Info.
General Notes:
1. I have to open EM and click the Design Package before I execute
(select Connection1 properties and point to physical location of the
first CSV)
2. WorkFlow is ActiveX to get Username -> passes this Username to
Connection 1 -> Import the CSV in Transform Data Task -> Connection 2
(My SQL 2000 Table) -> execute SQL Task with the above SQL Statement
3. I had to use Justin Engleman's Hack to fool the SQL Task
parameter:
How to trick it so the Execute SQL Task will work as I stated (note
one
other addition, need to give the ? a column name):
In the Execute SQL Task properties window
1) change the sql statement to: "select * from tbl_TempContact where 1
=
?" -- this is a statement that it can parse and will let you set
parameters
for
2) click the parameters button and and set the first parameter to your
global variable
3) change the sql statement to:
SELECT ? as colName, *
INTO tbl_NewTempContact
FROM tbl_TempContact
4) click OK and run your package
if you try to parse the sql statement in step 3 you will get a syntax
error,
same with if you try to click the parameters button at that point...
but if
you run the package you will see that it works fine
Hope this works for you, I know it's a bit clugy, but it does what I
need it to do, now if I could find an easy way to run this from a web
application, specifically prompt a user to upload the CSV to temp
location and have the DTS go to that temporary location and process.
Len |