I'm running batch processes via a batch file and I want SQL server to log the reslt when I execute my DBCC SHRINKFILE command from my batch file. Is there anyway to do this?
Example: - Run.bat
rem Shrink transaction log and log the result
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\osql.exe" -E -Q "Use [Database] DBCC SHRINKFILE(Database_log, 50)"
If you're just trying to log it to a text file you can do something like the following:
"C:\Program Files\Microsoft SQL Server\100\Tools\Binn\osql.exe" -E -Q "Use [Database] DBCC SHRINKFILE(Database_log, 50)" >> C:\ShrinkFile.LOG
The >> will append or > to overwrite.
If you want SQL server to actually log it in the error log then I would suggest looking into a trace flag that would handle that.