This project is read-only.

Connecting the SMO Events

Sep 23, 2007 at 11:05 PM
I'm trying to connect to the SQL Management Objects to output server messages to a file while a create database script runs with the 1.0 release.

Running the following works:
. .\EventHandler.ps1
$DatabaseServer = new-object ('Microsoft.SqlServer.Management.Smo.Server') "MYSERVER"
$ConnectionContext = $DatabaseServer.ConnectionContext
Get-EventBinding ConnectionContext -IncludeUnboundEvents | Format-Table -Auto

But I hit a road block at:
Add-EventHandler (get-variable ConnectionContext) ServerMessage { Write-Host "Foo"; } 
Add-EventHandler (get-variable ConnectionContext) InfoMessage { Write-Host "Foo"; }

With the following error:
  • Connect-EventListener : Unable to cast object of type 'Microsoft.SqlServer.Management.Common.ServerConnection' to type 'System.Management.Automation.PSObject'.

Thoughts on work arounds?

Sep 30, 2007 at 8:24 PM
Hi Colin,

I have SQL server SMO at home here, I'll take a closer look at what's happening and report back here!


- Oisin