Symptoms
«40002: 37000(Microsoft) ODBC SQL Server Driver (SQL Server) the Cursor was not Declared»
This error occurs after entering a user’s database login credentials when setting a company as default.
Cause
The user does not have the appropriate rights to the SQL database.
Resolution
Check the rights for the user to the Company Database. In order for users to pass authentication to the database in FRx Designer, users must have at least DataReader rights to the database.
References
Need more help?
Want more options?
Explore subscription benefits, browse training courses, learn how to secure your device, and more.
Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.
I am connecting to SQL Server via Spring in WebSphere. I have a piece of pretty simple dynamic SQL (below) that is throwing «The cursor was not declared.»
SELECT TOP 1
short_desc shortDescription
FROM
product.prs.PRODUCT_SKN (nolock)
WHERE
prod_sales_div_code = 'XXX'
AND product_nbr = ?
One of the settings for the data source that seems relevant is the «select mode» is «cursor». I’m not really sure what I need to do to resolve the error.
edit The calling code is:
findShortDescriptionQuery.get().findObjectByNamedParam(of("productNumber", productId))
asked Oct 19, 2011 at 16:37
RayRay
4,7994 gold badges28 silver badges55 bronze badges
4
Try saying WITH (nolock)
rather than just (nolock)
. The latter syntax is no longer supported on recent versions of sql server.
answered Oct 19, 2011 at 16:43
Joel CoehoornJoel Coehoorn
396k113 gold badges565 silver badges792 bronze badges
0
I removed the «nolock» directive altogether, along with the «TOP 1», and the problem went away. This makes me suspect it is related to the JDBC driver.
This workaround is less than ideal, but will work just fine for my purpose.
answered Oct 20, 2011 at 13:44
RayRay
4,7994 gold badges28 silver badges55 bronze badges
Check which database on the server you’re using. If you have different databases at the same server, your sql client will by default usually pick «master» or some such to run the query against if you don’t specify. Selecting the one that contains the table you’re querying or using USE <dbname> GO
before the query will handle the error.
answered Dec 27, 2017 at 22:40
DILPDILP
7499 silver badges13 bronze badges
I don’t know how much relevance this answer may have, after 10 years, but working on some old code I stumbled upon this same «error», and I solved it by removing the field list from the query, leaving the inefficient SELECT *
. This solved the problem for me.
BTW, the old code uses Microsoft SQL Server ODBC drivers to access the SQL Server, and it seems that the problem is exactly that, ’cause the same query run on SSMS works without issues’.
answered Oct 20, 2021 at 9:42
I had recently same issue..
Solved the problem by rewriting all queries with CTE.
WITH CTE
AS
(
SELECT..
)
SELECT * FROM CTE
Currently looking for same issue with stored procedures called from Internet Information Services.
buddemat
4,46713 gold badges26 silver badges49 bronze badges
answered Mar 18, 2022 at 11:25
в основном запросе, и подзапросе, для таблицы product задан один и тот же псевдоним, да и не нужно тебе еще раз обращаться к таблице продуктов + ты приравниваешь результат запроса, значит от подзапроса ожидается только одна запись, а у тебя их будет больше одного, используй in
p.model in (select model from printer pr)
Можно проверку на принтеры выполнить через exists
Oracle 11 SQL | ||
|
I was not declaring a cursor in VB. I have since added the following code(see below) and the declare cursor error is corrected but now I receive the following error on both databases.
Error Message: Error in fOpenExpOrd = [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name ‘CustTable’ err.Number = -2147217865
Code:
oConn.Open «Driver={SQL Server};» & _
«Server=MyServerName;» & _
«Database=myDatabaseName;» & _
«Uid=myUsername;» & _
«Pwd=myPassword»
Set rsADOAXOrdHdr = New ADODB.Recordset
rsADOAXOrdHdr.CursorType = adOpenKeyset
rsADOAXOrdHdr.LockType = adLockOptimistic
rsADOAXOrdHdr.Open «CustTable», oConn, , , adCmdTable
Error occurs on the open, Table name is correct.
Thanks for any help
October 1, 2007 at 7:55 am
#76790
When I ran trace for one of the application on which users are complaining about slowness, I found the following errors,
Error: 16945, Severity: 16, State: 1
Error: 16937, Severity: 16, State: 1
Error: 16954, Severity: 10, State: 1 — This one repeated like 20 times in a 30seconds trace.
Are these should be worried about? I know these are application related SQL cursor errors, but would like to know why these are caused as i couldn’t get proper answer from searching google.
Will these errors effect performance?
Lowell
SSC Guru
Points: 323498
select * from master.dbo.sysmessages where error = 16945
select * from master.dbo.sysmessages where error = 16937
select * from master.dbo.sysmessages where error = 16954
error = 16945: The cursor was not declared.
error = 16937: A server cursor is not allowed on a remote stored procedure or stored procedure with more than one SELECT statement. Use a default result set or client cursor.
error = 16954: Executing SQL directly; no cursor.
lookslike the cursor was not declared in some code, and is resulting int he errors you are seeing.
can you track down what is calling the code?
Lowell
—help us help you! If you post a question, make sure you include a CREATE TABLE… statement and INSERT INTO… statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!
noeld
SSC Guru
Points: 96590
this is just another reason to get rid of cursors … 😀
* Noel