Skip to content

Instantly share code, notes, and snippets.

@spaghettidba
Created August 26, 2019 14:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spaghettidba/8f0d97d7ee8d114d2526bb52e7bec931 to your computer and use it in GitHub Desktop.
Save spaghettidba/8f0d97d7ee8d114d2526bb52e7bec931 to your computer and use it in GitHub Desktop.
Trace DLLs
#
# RUN THIS CODE IN Powershell x86 !!!!!
#
$dllPath = "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\PFCLNT.DLL"
$typeName = "Microsoft.SqlServer.Management.Trace.CTraceObjectsFileController"
try {
#
# this is the code found in Microsoft.SqlServer.Management.Trace.TraceFile.InitializeAsReader (thanks DotPeek...)
#
$InputFile = "c:\temp\test.trc"
$baseAssembly = [Reflection.Assembly]::LoadFrom($dllPath)
$instance = $baseAssembly.CreateInstance($typeName, $true, [System.Reflection.BindingFlags]::IgnoreCase -bor [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::Public -bor [System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::CreateInstance, $null, $null, $null, $null);
$instance.Initialize($InputFile)
$instance.InitSource($false)
}
catch {
$_.Exception | Select-Object *
}
# ErrorRecord : Exception calling "InitSource" with "1" argument(s): ""
# WasThrownFromThrowStatement : False
# Message : Exception calling "InitSource" with "1" argument(s): ""
# Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
# InnerException : System.InvalidOperationException
# at ?A0xd87a39eb.ProcessError(Int32 hr, UInt16* lpszMessage)
# at Microsoft.SqlServer.Management.Trace.CTraceControllerBase.InitSource(Boolean
# bReOpen)
# at CallSite.Target(Closure , CallSite , Object , Boolean )
# TargetSite : Void CheckActionPreference(System.Management.Automation.Language.FunctionContext,
# System.Exception)
# StackTrace : at
# System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext
# funcContext, Exception exception)
# at
# System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame
# frame)
# at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interp
# retedFrame frame)
# at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(Interp
# retedFrame frame)
# HelpLink :
# Source : System.Management.Automation
# HResult : -2146233087
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment