alexzen
asked on
Call a stored procedure without using CRecordset...
Hello, everyone.
Could anyone show me how to call a stored procedure which returns a value in VC++? (WITHOUT using CRecordeset)
I searched and got a few answers here but those were not what I wanted. Let me explain what I need for my project.
It's a multi-threaded program, and each thread must call the stored procedure continually while running. The stored procedure is like the bottom:
CREATE PROCEDURE GetMyNum
@In_MyStr varchar(15),
@Out_Result smallint OUTPUT
AS
SET @In_MyStr = RTRIM(LTRIM(@In_MyStr))
SET @Out_Result = 0
SELECT @Out_Result = theNum
FROM NumTable
WHERE theStr = @In_MyStr
I am from VB so it's very easy to do this with a Command object without using any recordset object. When I looked at a sample VC++ code somewhere and I was just lost.
There are several ways to accomplish the logic above. The reason why I chose this scenario is that I thought it might be better for performance (speed mostly).
Let me elaborate my logic a little bit.
My thought is that:
- Create a global connection object when the program starts.
- Create threads and they are going to use the connection object for its Command object's ActiveConnection.
- When I need a number from database, I call the stored procedure through the command object and get the value from the command object without even bothering with a CRecordset object.
Thank you in advance for any input.
Happy programming.
Could anyone show me how to call a stored procedure which returns a value in VC++? (WITHOUT using CRecordeset)
I searched and got a few answers here but those were not what I wanted. Let me explain what I need for my project.
It's a multi-threaded program, and each thread must call the stored procedure continually while running. The stored procedure is like the bottom:
CREATE PROCEDURE GetMyNum
@In_MyStr varchar(15),
@Out_Result smallint OUTPUT
AS
SET @In_MyStr = RTRIM(LTRIM(@In_MyStr))
SET @Out_Result = 0
SELECT @Out_Result = theNum
FROM NumTable
WHERE theStr = @In_MyStr
I am from VB so it's very easy to do this with a Command object without using any recordset object. When I looked at a sample VC++ code somewhere and I was just lost.
There are several ways to accomplish the logic above. The reason why I chose this scenario is that I thought it might be better for performance (speed mostly).
Let me elaborate my logic a little bit.
My thought is that:
- Create a global connection object when the program starts.
- Create threads and they are going to use the connection object for its Command object's ActiveConnection.
- When I need a number from database, I call the stored procedure through the command object and get the value from the command object without even bothering with a CRecordset object.
Thank you in advance for any input.
Happy programming.
ASKER
Thank you for your comment, Triskelion.
Could you elaborate what is PRO*C??
Thanks
Could you elaborate what is PRO*C??
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, Triskelion.
Alas, we are a Microsoft Shop.. so I'm using MS SQL server.
Thank you anyway.
Alas, we are a Microsoft Shop.. so I'm using MS SQL server.
Thank you anyway.
You can call CDatabase::ExecuteSQL(), but AFAIK, it's only good for stored procedures that do not have result sets.
If you want to use a CRecordset, there are a few techniques.