I am trying to run a DTS package using the ActiveX task to export files from a table in SQL Server using the ADODB.Stream method. I am using the following code:
Connection:
set myConn = CreateObject("ADODB.Connection")
myConn.Open = "Provider=SQLOLEDB.1;Data Source=servername;Initial Catalog=databasename;user id = 'userID';password='password'"
Recordset:
set rst = CreateObject("ADODB.Recordset")
rst.Open strSQL, myConn
Write from Stream:
Do Until rst.EOF
Set mstream = CreateObject("ADODB.Stream")
mstream.mode = adModeReadWrite
mstream.Open
mstream.Write rst.Fields("doccontent").Value
mstream.SaveToFile strPath, strDocName, adSaveCreateOverWrite
mstream.Close
rst.movenext
Loop
This code is erroring out on the "mstream.Write" line. I get the following error:
"Operation is not allowed in this context."
This is the error as it appears in the error log:
Error on Line 67
(ADODB.Stream (800a0c93): Operation is not allowed in this context.)
Step Error code: 800403FE
Step Error Help File:sqldts80.hlp
Step Error Help Context ID:1100
Any help on how to get this to work properly would be greatly appreciated. This method works in Visual Basic, but I would like to run it from a DTS package -- so I know the data is being pulled properly. I'm just not sure if I am connecting or opening the stream correctly in SQL Server.
Thanks,
ejc
Connection:
set myConn = CreateObject("ADODB.Connection")
myConn.Open = "Provider=SQLOLEDB.1;Data Source=servername;Initial Catalog=databasename;user id = 'userID';password='password'"
Recordset:
set rst = CreateObject("ADODB.Recordset")
rst.Open strSQL, myConn
Write from Stream:
Do Until rst.EOF
Set mstream = CreateObject("ADODB.Stream")
mstream.mode = adModeReadWrite
mstream.Open
mstream.Write rst.Fields("doccontent").Value
mstream.SaveToFile strPath, strDocName, adSaveCreateOverWrite
mstream.Close
rst.movenext
Loop
This code is erroring out on the "mstream.Write" line. I get the following error:
"Operation is not allowed in this context."
This is the error as it appears in the error log:
Error on Line 67
(ADODB.Stream (800a0c93): Operation is not allowed in this context.)
Step Error code: 800403FE
Step Error Help File:sqldts80.hlp
Step Error Help Context ID:1100
Any help on how to get this to work properly would be greatly appreciated. This method works in Visual Basic, but I would like to run it from a DTS package -- so I know the data is being pulled properly. I'm just not sure if I am connecting or opening the stream correctly in SQL Server.
Thanks,
ejc