assigning results of a user stored procedure (select) to a recordset

I am defining my SQL statments as user stored procedures (usp's)  in SQLServer. I normally pass parameters, eg @table_id, to and from the usp. Now, however, I want to store the results of my query in a recordset, using the following code:
var cn = new ActiveXObject("ADODB.Connection");
var rs1 = new ActiveXObject("ADODB.Recordset");
var cm = new ActiveXObject("ADODB.Command");
cm.CommandText = "dbo.usp_selectstatus";
cm.CommandType = 4;
cm.Prepared = true;
cm.Parameters.Refresh();
rs1.Open(cm.Execute(), cn);

I know the problem is with the final line of code shown here, and tried to write it like
rs1 = cm.Execute();,
but the error I get is :
The application requested an operation on an object with a reference to a closed or invalid Connection object.

Can you tell me what the correct code would be to establish the connection, etc.?

thanks
Clo
clodaghmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MarineCommented:
dim Cn as adodb.connection
dim rs as adodb.recordset
dim cmd as adodb.command

cn.connectionstring = "DRIVER=SQL SERVER";Server="specifyserver";UID="UID";PWD="password";Database=database"
cn.open

cm.activeconnection = cn
cm.CommandText="dbo.usp_selectstatus";
cm.CommandType = 4;
cm.Prepared = true;
rs.open cm.execute(),cn
0
clodaghmAuthor Commented:
rs.open cm.execute(),cn
Would you know the syntax for this in Jscript as opposed to VBscript?
0
robbertCommented:
clodaghm,

1. You did not open the connection (cn.Open "DSN=myDSN;UID=myUID;PWD=myPWD")
2. What does (cm.Execute(), cn) return, as a string?
3. rs.open cm.execute(),cn
is
rs.Open(cm.Execute(),cn)
in JavaScript.
0
Yury_DelendikCommented:
Try

var cn = new ActiveXObject("ADODB.Connection");
var rs1 = new ActiveXObject("ADODB.Recordset");
var cm = new ActiveXObject("ADODB.Command");
cm.CommandText = "dbo.usp_selectstatus";
cm.CommandType = 4;
cm.Prepared = true;
cm.Parameters.Refresh();

rs1.Open(cm, cn)

or

cm.ActiveConnection = cn;
rs1 = cm.Execute();

Don't forget about cn.Open(".....");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.