SQL Server Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘cursor’

FIX: DB-Library sp_cursor Fails with Error Message 16933 if Bracketed Identifiers are Passed with the Tablename Parameter

Symptoms
When you use the DB-Library API server cursors, if the table name parameter that is passed to the sp_cursor stored procedure includes a bracketed identifier, the execution of sp_cursor fails with the following error message:

SQL Server message 16933, state 2, severity 16:
The cursor does not include the table being modified or the table is not updatable through the cursor.Refer to the “More Information” section of this article for an example and additional symptoms.
Resolution
SQL Server is unable to successfully parse the bracketed table name with spaces.
DB-Library binds the table name as a SQLCHAR data type, which has a fixed length of 255 characters (the maximum length of this data type). The buffer holds the table name, including the brackets, with the remaining bytes padded with spaces.

FIX: When you update rows by using a cursor in SQL Server 2008, the update may take a long time to finish

Symptoms
In Microsoft SQL Server 2008, you create a cursor. You try to update the cursor by using a statement. The statement includes an ORDER BY clause. When you update rows by using the cursor, the update may take a long time to finish.
This problem also occurs in Microsoft SQL Server 2005. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
955694?(http://support.microsoft.com/kb/955694/) FIX: When you update rows by using a cursor in SQL Server 2005, the update may take a long time to finish
Resolution
The fix for this issue was first released in Cumulative Update 1. For more information about how to obtain this cumulative update package for SQL Server 2008, click the following article number to view the article in the Microsoft Knowledge Base:
956717?(http://support.microsoft.com/kb/956717/) Cumulative update package 1 for SQL Server 2008Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
956909?(http://support.microsoft.com/kb/956909/) The SQL Server 2008 builds that were released after SQL Server 2008 was released
Additional informationThe following sections include important information about the fix.Steps to enable the fixIn SQL Server Configuration Manager, add the -T4128 startup parameter to the instance of SQL Server. To do this, follow these steps:In SQL Server Configuration Manager, click SQL Server Services.In the right pane, right-click SQL Server (instance_name), and then click Properties.In the Properties dialog box, click the Advanced tab.On the Advanced tab, locate the Startup Parameters item, and then type -T4128 at the end of the existing value.
Note Separate the parameter from other parameters by using a semicolon (;).Click OK, and then close SQL Server Configuration Manager.Restart the SQL Server 2008 database engine service for the trace flag to take effect.Issues that the fix addressesThe fix addresses this issue when the following conditions are true:The user is updating by using a cursor. This can be identified from the Showplan by the UPDATE CURSOR operator.Before the execution of a Clustered Index Update statement, a Nested Loop statement is executed. This statement includes a cursor work table (CWT) that is used as a object, together with the Inner Join parameter. Then, the CWT object is used in the Clustered Index Statement as part of the execution plan for the node.There is an ORDER BY clause in the DECLARE CURSOR (or equivalent API) statement. You can only determine this with certainty by verifying the DECLARE CURSOR statement text.