Perform ExecuteNonQuery Against SQL Database

This is a script that performs an ExecuteNonQuery commands against a SQL database. This script has a modular function that performs the commands necessary to establish, open, close and execute the database connection and commands. To perform queries, simply pass the connection st

ExecNonQuery.ps1
 
 
 
 
 
3.5 Star
(4)
2,123 times
Add to favorites
Databases
8/17/2011
E-mail Twitter del.icio.us Digg Facebook
  • Catching exceptions
    1 Posts | Last post May 03, 2013
    • Hello Nathon,
      In your script you catch any SqlException and report it as a possible locked row, while I'm sure a locked row could cause this, many other things could throw this exception as well. Here is a snippet that tells the user the exact error coming back from SQL:
      catch [System.Data.SqlClient.SqlException] 
      { 
      	$_ | select -expandproperty invocationinfo | Format-List Line, PositionMessage -force 
      	write-host $_.Exception.ToString() -foregroundcolor "red"	
      }