Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hangs when calling SP that uses a cursor #48

Closed
IGx89 opened this issue Feb 21, 2022 · 5 comments
Closed

Hangs when calling SP that uses a cursor #48

IGx89 opened this issue Feb 21, 2022 · 5 comments

Comments

@IGx89
Copy link

IGx89 commented Feb 21, 2022

Any time I attempt to call a stored proc that iterates over a cursor, the tool hangs. Using this command:

sqlcmd -Q "exec TestSqlCmd" -S "DatabaseServer" -U DatabaseUser -d DatabaseName

and the following variations of the stored proc:

CREATE PROCEDURE [dbo].[TestSqlCmd]
AS
BEGIN
	DECLARE @tmp int;

	DECLARE Server_Cursor CURSOR FOR
	SELECT 1 UNION SELECT 1

	OPEN Server_Cursor;
	FETCH NEXT FROM Server_Cursor INTO @tmp;
	WHILE @@FETCH_STATUS = 0
		BEGIN
			FETCH NEXT FROM Server_Cursor INTO @tmp;
		END;
	CLOSE Server_Cursor;
	DEALLOCATE Server_Cursor;
END

GO
CREATE PROCEDURE [dbo].[TestSqlCmd]
AS
BEGIN
	DECLARE @tmp int;

	DECLARE Server_Cursor CURSOR FOR
	SELECT 1 UNION SELECT 1

	OPEN Server_Cursor;
	CLOSE Server_Cursor;
	DEALLOCATE Server_Cursor;
END

GO

The command hangs indefinitely. Strangely, if I remove the DEALLOCATE like so it works:

CREATE PROCEDURE [dbo].[TestSqlCmd]
AS
BEGIN
	DECLARE @tmp int;

	DECLARE Server_Cursor CURSOR FOR
	SELECT 1 UNION SELECT 1

	OPEN Server_Cursor;
	CLOSE Server_Cursor;
END

GO

but if I attempt doing so with the full SP it still hangs:

CREATE PROCEDURE [dbo].[TestSqlCmd]
AS
BEGIN
	DECLARE @tmp int;

	DECLARE Server_Cursor CURSOR FOR
	SELECT 1 UNION SELECT 1

	OPEN Server_Cursor;
	FETCH NEXT FROM Server_Cursor INTO @tmp;
	WHILE @@FETCH_STATUS = 0
		BEGIN
			FETCH NEXT FROM Server_Cursor INTO @tmp;
		END;
	CLOSE Server_Cursor;
END

GO

Every single one of the variations above work just fine using the standard sqlcmd tool. I've tested on a local SQL Server database and an Azure SQL Server database with same results, so it doesn't appear to be server-specific.

@shueybubbles
Copy link
Collaborator

@IGx89 can you try it with an earlier preview build to see if perhaps it was broken by facd5a0

@IGx89
Copy link
Author

IGx89 commented Feb 23, 2022

@shueybubbles your theory is correct, this issue doesn't happen on v0.2.0. I'll use that version until this bug is fixed, thanks a lot for the workaround!

@shueybubbles
Copy link
Collaborator

opened a PR for the driver fix denisenkom/go-mssqldb#723

@shueybubbles
Copy link
Collaborator

Please try version v0.4.0

@IGx89
Copy link
Author

IGx89 commented Mar 8, 2022

Please try version v0.4.0

Confirmed working, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants