dbTalk Databases Forums  

Create ADO Recordset in DTS VBScript

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Create ADO Recordset in DTS VBScript in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Julie Pemberton
 
Posts: n/a

Default Create ADO Recordset in DTS VBScript - 09-18-2003 , 09:20 AM






Hi,

In an ActiveX VBScript I need to be able to create a
recordset in code.

Normally, I would use the ExecuteSQLTask, load it into a
Global Variable and set rs = DTSGlobalVariables
("gvRS").Value and then use the recordset. This won't
work because the SQL I want to execute is "SELECT
SeqNumber, CompanyNumber FROM ?" The execute SQL task
will only allow an input variable from the where clause,
it will not accept a ? as a TableName which is what I need
to pass to it.

I have successfully created a custom DTSexecuteSQL:
Set oSQLTask=oPackage.Tasks.New ("DTSExecuteSQLTask")

And successfully executed SQL in Tables using
the "oPackage.Steps("AutoSQLExecute").Execute"

If I create the SQL and try to "set rs = oPackage.Steps
("AutoSQLExecute").Execute" It gives me an error.

Can anyone tell me how to create and ADO Recordset in
VBScript that will work in a DTS ActiveXScript?

Thanks!



Reply With Quote
  #2  
Old   
JFB
 
Posts: n/a

Default Re: Create ADO Recordset in DTS VBScript - 09-18-2003 , 10:00 AM






Hi Julie
Here is an example:
JFB

'************************************************* *********************
' Visual Basic ActiveX Script
'************************************************* ***********************

Function Main()
Dim countr
' Connection to SQL
set mySourceConn=CreateObject("ADODB.Connection")
set mySourceRecordset=CreateObject("ADODB.Recordset")
mySourceConn.Open="Provider=SQLOLEDB;Trusted_Conne ction=yes; Data
Source=ServerName; Initial Catalog=Northwind; user id='user';
password='pwd'"

mySQLCmdText= "select orderID from orders"
mySourceRecordset.open mySQLCmdText, mySourceConn
msgbox mySQLCmdText
msgbox mySourceRecordset.RecordCount

If IsNull(mySourceRecordset.EOF) or (mySourceRecordset.cachesize < 1)
Then
num=1
Else
For countr =1 to mySourceRecordset.RecordCount
num=mySourceRecordset.Fields("orderID").value
mySourceRecordset.MoveNext
Next

End if
mySourceRecordset.close
Main = DTSTaskExecResult_Success
End Function

"Julie Pemberton" <JPemberton (AT) Prac (DOT) Com> wrote

Quote:
Hi,

In an ActiveX VBScript I need to be able to create a
recordset in code.

Normally, I would use the ExecuteSQLTask, load it into a
Global Variable and set rs = DTSGlobalVariables
("gvRS").Value and then use the recordset. This won't
work because the SQL I want to execute is "SELECT
SeqNumber, CompanyNumber FROM ?" The execute SQL task
will only allow an input variable from the where clause,
it will not accept a ? as a TableName which is what I need
to pass to it.

I have successfully created a custom DTSexecuteSQL:
Set oSQLTask=oPackage.Tasks.New ("DTSExecuteSQLTask")

And successfully executed SQL in Tables using
the "oPackage.Steps("AutoSQLExecute").Execute"

If I create the SQL and try to "set rs = oPackage.Steps
("AutoSQLExecute").Execute" It gives me an error.

Can anyone tell me how to create and ADO Recordset in
VBScript that will work in a DTS ActiveXScript?

Thanks!





Reply With Quote
  #3  
Old   
Julie Pemberton
 
Posts: n/a

Default Re: It Worked! - 09-18-2003 , 01:18 PM



This worked great.

Thanks!

Quote:
-----Original Message-----
Hi Julie
Here is an example:
JFB

'************************************************* ********
*************
' Visual Basic ActiveX Script
'************************************************* ********
***************

Function Main()
Dim countr
' Connection to SQL
set mySourceConn=CreateObject("ADODB.Connection")
set mySourceRecordset=CreateObject("ADODB.Recordset")
mySourceConn.Open="Provider=SQLOLEDB;Trusted_Conne ction=ye
s; Data
Source=ServerName; Initial Catalog=Northwind; user
id='user';
password='pwd'"

mySQLCmdText= "select orderID from orders"
mySourceRecordset.open mySQLCmdText, mySourceConn
msgbox mySQLCmdText
msgbox mySourceRecordset.RecordCount

If IsNull(mySourceRecordset.EOF) or
(mySourceRecordset.cachesize < 1)
Then
num=1
Else
For countr =1 to mySourceRecordset.RecordCount
num=mySourceRecordset.Fields("orderID").value
mySourceRecordset.MoveNext
Next

End if
mySourceRecordset.close
Main = DTSTaskExecResult_Success
End Function

"Julie Pemberton" <JPemberton (AT) Prac (DOT) Com> wrote in message
news:04b001c37def$fe1ac990$3101280a (AT) phx (DOT) gbl...
Hi,

In an ActiveX VBScript I need to be able to create a
recordset in code.

Normally, I would use the ExecuteSQLTask, load it into a
Global Variable and set rs = DTSGlobalVariables
("gvRS").Value and then use the recordset. This won't
work because the SQL I want to execute is "SELECT
SeqNumber, CompanyNumber FROM ?" The execute SQL task
will only allow an input variable from the where clause,
it will not accept a ? as a TableName which is what I
need
to pass to it.

I have successfully created a custom DTSexecuteSQL:
Set oSQLTask=oPackage.Tasks.New ("DTSExecuteSQLTask")

And successfully executed SQL in Tables using
the "oPackage.Steps("AutoSQLExecute").Execute"

If I create the SQL and try to "set rs = oPackage.Steps
("AutoSQLExecute").Execute" It gives me an error.

Can anyone tell me how to create and ADO Recordset in
VBScript that will work in a DTS ActiveXScript?

Thanks!




.


Reply With Quote
  #4  
Old   
Darren Green
 
Posts: n/a

Default Re: Create ADO Recordset in DTS VBScript - 09-18-2003 , 02:49 PM



In article <04b001c37def$fe1ac990$3101280a (AT) phx (DOT) gbl>, Julie Pemberton
<JPemberton (AT) Prac (DOT) Com> writes
Quote:
Hi,

In an ActiveX VBScript I need to be able to create a
recordset in code.

Normally, I would use the ExecuteSQLTask, load it into a
Global Variable and set rs = DTSGlobalVariables
("gvRS").Value and then use the recordset. This won't
work because the SQL I want to execute is "SELECT
SeqNumber, CompanyNumber FROM ?" The execute SQL task
will only allow an input variable from the where clause,
it will not accept a ? as a TableName which is what I need
to pass to it.

I have successfully created a custom DTSexecuteSQL:
Set oSQLTask=oPackage.Tasks.New ("DTSExecuteSQLTask")

And successfully executed SQL in Tables using
the "oPackage.Steps("AutoSQLExecute").Execute"

If I create the SQL and try to "set rs = oPackage.Steps
("AutoSQLExecute").Execute" It gives me an error.

Can anyone tell me how to create and ADO Recordset in
VBScript that will work in a DTS ActiveXScript?

Thanks!

You can still use the Execute SQL Task, by manipulating the SQL outside
of the task and the parameters function, using an ActiveX Script Task.

I like this method as you only need DTS connections as opposed to
maintaining connection properties into multiple places, but if it works
for you, go with what you have from JFB-

Global Variables and SQL statements in DTS
(http://www.sqldts.com/default.aspx?205)
--
Darren Green (SQL Server MVP)
DTS - http://www.sqldts.com

PASS - the definitive, global community for SQL Server professionals
http://www.sqlpass.org



Reply With Quote
  #5  
Old   
bureaucratusmaximus@yahoo.com
 
Posts: n/a

Default Re: Create ADO Recordset in DTS VBScript - 02-01-2005 , 01:25 PM



JFB wrote:
Quote:
Hi Julie
Here is an example:
JFB


'************************************************* *********************
' Visual Basic ActiveX Script

'************************************************* ***********************

Function Main()
Dim countr
' Connection to SQL
set mySourceConn=CreateObject("ADODB.Connection")
set mySourceRecordset=CreateObject("ADODB.Recordset")
mySourceConn.Open="Provider=SQLOLEDB;Trusted_Conne ction=yes; Data
Source=ServerName; Initial Catalog=Northwind; user id='user';
password='pwd'"

mySQLCmdText= "select orderID from orders"
mySourceRecordset.open mySQLCmdText, mySourceConn
msgbox mySQLCmdText
msgbox mySourceRecordset.RecordCount

If IsNull(mySourceRecordset.EOF) or (mySourceRecordset.cachesize
1)
Then
num=1
Else
For countr =1 to mySourceRecordset.RecordCount
num=mySourceRecordset.Fields("orderID").value
mySourceRecordset.MoveNext
Next

End if
mySourceRecordset.close
Main = DTSTaskExecResult_Success
End Function

"Julie Pemberton" <JPemberton (AT) Prac (DOT) Com> wrote in message
news:04b001c37def$fe1ac990$3101280a (AT) phx (DOT) gbl...
Whoa...how was it that mySourceRecordset.RecordCount evaluated to
something other than -1? I had to specify:

mySourceRecordset.open mySQLCmdText, mySourceConn,3
mySourceConn.CursorLocation = 3

to get RecordCount to eval to something other than -1. (3 is the
CursorType equivalent to adUseClient and 3 is the CursorLocation
constant equivalent to adUseClient) I couldn't get a RecordCount on an
ADO recordset through DTS any other way.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.