Skip to content

Instantly share code, notes, and snippets.

@spaghettidba
Created August 26, 2019 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spaghettidba/f7306ffc511b1dd10540e2f91517a9a8 to your computer and use it in GitHub Desktop.
Save spaghettidba/f7306ffc511b1dd10540e2f91517a9a8 to your computer and use it in GitHub Desktop.
Trace DLLs 2
#
# RUN THIS CODE IN Powershell x86 !!!!!
#
$dllPath = "C:\Program Files (x86)\Microsoft SQL Server Management Studio 18\Common7\IDE\Microsoft.SqlServer.ConnectionInfoExtended.dll"
$typeName = "Microsoft.SqlServer.Management.Trace.Tracefile"
try {
$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.InitializeAsReader($InputFile)
}
catch {
$_.Exception | Select-Object *
}
# ErrorRecord : Exception calling "InitializeAsReader" with "1" argument(s): "Failed to initialize
# object as reader."
# WasThrownFromThrowStatement : False
# Message : Exception calling "InitializeAsReader" with "1" argument(s): "Failed to initialize
# object as reader."
# Data : {System.Management.Automation.Interpreter.InterpretedFrameInfo}
# InnerException : Microsoft.SqlServer.Management.Trace.SqlTraceException: Failed to initialize object as
# reader. ---> System.NullReferenceException: Object reference not set to an instance of
# an object.
# at Microsoft.SqlServer.Management.Trace.TraceFile.InitializeAsReader(String fileName)
# --- End of inner exception stack trace ---
# at Microsoft.SqlServer.Management.Trace.TraceFile.InitializeAsReader(String fileName)
# at CallSite.Target(Closure , CallSite , Object , Object )
# 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