PRB: Keyset Cursor to Access a Remoted Table Through a Linked Server May Cause Error 16953 (269694)
The information in this article applies to:
This article was previously published under Q269694 SYMPTOMS
When you declare a KEYSET cursor to access a remote table on a linked server, the cursor might not be created and an error message might occur. The same behavior occurs when Microsoft SQL Server converts other cursor types to KEYSET cursors.
Both of the following cursor declarations cause the 16953 error message to occur:
DECLARE TEST_CURSOR CURSOR
KEYSET
FOR
SELECT *
FROM LinkedServer1.pubs.dbo.authors
DECLARE TEST_CURSOR CURSOR
FOR
SELECT *
FROM LinkedServer1.pubs.dbo.authors
The text of the error message is:
Server: Msg 16953, Level 16, State 1, Line 3
Updatable keyset cursors on remote tables require a transaction with
the REPEATABLE_READ or SERIALIZABLE isolation level.
If you subsequently open the cursor by using
open TEST_CURSOR
the following error message occurs:
Server: Msg 16916, Level 16, State 1, Line 1
A cursor with the name 'TEST_CURSOR' does not exist.
CAUSE
This behavior is by design.
WORKAROUND
To work around this behavior, use one of the following methods:
- Set the transaction Isolation level to REPEATABLE READ or SERIALIZABLE, and then wrap the cursor operations in a transaction. For example, you can use the following code:
set transaction isolation level repeatable read
Begin tran
DECLARE TEST_CURSOR CURSOR
KEYSET
FOR
SELECT *
FROM LinkedServer1.pubs.dbo.authors
open TEST_CURSOR
--do your work
deallocate TEST_CURSOR
commit tran
set transaction isolation level read committed
-or-
- Use a STATIC or INSENSITIVE cursor. The following two cursor declarations work.
DECLARE TEST_CURSOR INSENSITIVE CURSOR
FOR
SELECT *
FROM LinkedServer1.pubs.dbo.authors
DECLARE TEST_CURSOR CURSOR
STATIC
FOR
SELECT *
FROM LinkedServer1.pubs.dbo.authors
Modification Type: | Major | Last Reviewed: | 10/28/2000 |
---|
Keywords: | kbprb KB269694 kbAudDeveloper |
---|
|