I have a SQL cmd script that looks like this:
:setvar DatabaseName testDb
:On Error Exit
--break point on next line
Declare @DBName varchar(255), @DBPath varchar(255), @LogName varchar(255), @LogPath varchar(255)
IF EXISTS (SELECT 1 FROM [master].[dbo].[sysdatabases] WHERE [name] = N'$(DatabaseName)')
BEGIN
USE [$(DatabaseName)];
select @DBName = name, @DBPath = physical_name from sys.database_files where type_desc = 'ROWS'
select @LogName = name , @LogPath = physical_name from sys.database_files where type_desc = 'LOG'
END
Print @dbname
Print @dbpath
When I try to debug the above script in SQL Server Management Studio, the line that is highlighted as the line that is currently being executed, doesn't seem to be the one that is executing. And based on looking at the locals window and when the @dbName
gets set, the debugger seems to be off by 4 lines (when the highlighted line is the declare line, the @dbname
gets set with the value from the database).
Wondering if it is because the debugger is skipping my setvar
statements. Also is there any work-around. It is extremely hard to debug a large script when the current line is not the current line!!!