Batch Files Tips
Created 08 October 2003 00:00

Catching unknown variables

If you want to run another batch command and want to pass it all the variables your batch file receives, you can use a loop to catch all the variables into a single string, and then open the other batch file with those same variables:

  @ECHO OFF
  SET tmp=SecondBatchFile
  GOTO LOOPFILES

  :LOOPFILES
    @ECHO OFF
    SET tmp=%tmp% %1
    SHIFT
    IF %1. == . GOTO END
    GOTO LOOPFILES
  :END
  ECHO ON
  %tmp%

Dates and Times

On Windows NT, use the %time% and %date% values to manipulate dates and times.


SET hour=%time:~0,2%
SET min=%time:~3,2%
SET sec=%time:~6,2%

ECHO %TIME%
ECHO %hour%:%min%:%sec%
.NET Debugging Tips
Created 03 October 2003 00:00
Conditional Debugging Attribute

You can use an attribute to to decorate a method so that the method will only be called whilst in debug mode: it gets ignored in release mode. For instance, you could have a method that displays useful information in debug but not release:

  [System.Diagnostics.Conditional("DEBUG")]
  private void DisplaySomeData()
  {
    // Display the data if in debug mode.
    this.TextBox1.Title = this.objectData.ToString();
  }

DebuggerStepThrough

Using this attribute you'll be able to debug whilst ignoring the decorated class or method. In the following example, the method will be ignored by the debugger:

  [System.Diagnostics.DebuggerStepThrough()]
  private void DoNothing()
  {
    return null;
  }

Debugging your applications without Visual Studio.NET

The .NET Framework comes with a debug tool called the CLR Debugger, and is located in the GuiDebug folder in the Framework folder on the machine where you installed the SDK.

To debug your application, add the /debug tag to your compilation script e.g. csc yourfile.cs /debug. This will create a .pdb file which contains the debugging information.

With the debugger, now select the exe that was generated by clicking "Debug" and then "Program to Debug". You can now run and debug your application with breakpoints etc just as you do in the standard Visual Studio.NET IDE.

SQL Server : Changing Object Ownership
Created 16 October 2003 00:00
For example, to change the owner of table MyTable to user MyUser, just run the predefined stored procedure sp_changeobjectowner:
  EXEC sp_changeobjectowner 'MyTable', 'MyUser'
SQL Server Cursors
Created 28 October 2003 00:00
You can use cursors in SQL Server stored procedures to process data already in the database and take action accordingly. These can be used just like recordsets within standard code - for example:
  CREATE PROCEDURE MyStoredProc
  AS
  DECLARE @ID int
  DECLARE @Desc varchar(100)
  DECLARE MyCursor CURSOR FOR 
    SELECT TOP 10 ID, Desc FROM MyTable

  OPEN MyCursor
  FETCH NEXT FROM MyCursor INTO @ID, @Desc

  WHILE @@FETCH_STATUS = 0
  BEGIN
    PRINT CAST(@ID as varchar(10)) + '--' + @Desc
    FETCH NEXT FROM MyCursor INTO @ID, @Desc
  END

  CLOSE MyCursor
  DEALLOCATE MyCursor