Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 stored procedure: COUNT field incorrect error

Author  Topic 

boxmonkey
Starting Member

23 Posts

Posted - 2005-02-28 : 18:40:37
Hello,
I've written a program using C++/MFC. I've overridden a CRecordSet class, and it works great for accessing tables and updating fields, however when I try to execute a stored procedure I get "COUNT field incorrect or syntax error".

The SP works fine in query analyzer, and is rather simple:
CREATE PROCEDURE sp_getcurrentmonth
AS SELECT TOP 1 month_id FROM lockdown_schedule WHERE lockdown_date + 7 > GETDATE() ORDER BY lockdown_date asc RETURN 0
GO

And here is how I call it in my program:

m_myDB.Open(CRecordset::forwardOnly,"{? = CALL sp_getcurrentmonth}",CRecordset::executeDirect|CRecordset::readOnly)

Am I missing something obvious?

Thanks.

Kristen
Test

22859 Posts

Posted - 2005-03-01 : 00:26:56
SProcs that are named "sp_xxx" are run from MASTER first, if they exist.

Might be worth looking for an SProc with that name in MASTER database - and perhaps not prefixing them with "sp_" in future! (There are performance ramifications too - every SProc executed will cause SQL to check MASTER DB first ... and if you are going to go to that trouble change your call to

Also check that there is not an addiitonal copy owned by the user that is attaching from the C++/MFC app [probably NOT dbo] (as distinct to the user you are logging on to Query Analyser with - [probably dbo] )

dbo.xxxsp_getcurrentmonth

so that SQL goes directly to DBO without checking for an SProc owned by the logged on user first.

Kristen
Go to Top of Page

boxmonkey
Starting Member

23 Posts

Posted - 2005-03-01 : 17:02:44
Thanks Kristen, that's good to know. I renamed it to usp_ for now just to see if that would help...but the error persists. Any other ideas?
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2005-03-02 : 15:02:20
I have had this error before, but its generally been a syntax error - and thus shows up in Query Analyser too. I can't see much wrong with the SP as you have it.

You could use Profiler to see the EXACT calling syntax from the Application, and then test that in Q.A. to double check that it behaves OK.

Kristen
Go to Top of Page

boxmonkey
Starting Member

23 Posts

Posted - 2005-03-03 : 14:59:02
Well it turns out it was a problem with the way the ODBC driver was parsing the call. When I removed the "? = " part, everything started working as expected.
Go to Top of Page
   

- Advertisement -