TraceFile.InitializeAsReader fails with “Failed to initialize object as reader”

  • Thread starter Thread starter stuart_isaac
  • Start date Start date
S

stuart_isaac

Guest
I'm trying to update an application that reads SQL Server trace files to work with SQL Server 2019. It always breaks with new major SQL Server versions, requiring updating to the latest SSMS version. With SQL Server 2019 and SSMS 18, though, I've been unable to get the InitializeAsReader method in Microsoft.SqlServer.Management.Trace.TraceFile to work. It always fails with Failed to initialize object as reader, with the following stack trace in the inner exception:

at ?A0x4b523f86.ProcessError(Int32 hr, UInt16* lpszMessage)
at Microsoft.SqlServer.Management.Trace.CTraceControllerBase.InitSource(Boolean bReOpen)
at Microsoft.SqlServer.Management.Trace.TraceFile.InitializeAsReader(String fileName)

I've seen various things here and there that refer to using x86, not 64-bit, and that doesn't seem to be the issue here. I can reproduce it with the following trivial application:

string path = @"pathtotracefile.trc";
TraceFile trace = new TraceFile();

if (File.Exists(path))
{
try
{
trace.InitializeAsReader(path);
Console.WriteLine("Did initialize");
}
catch (SqlTraceException ex)
{
Console.WriteLine("Exception :(");
}
}
else
{
Console.WriteLine("No such file");
}
Can someone suggest what might be going wrong here?

Continue reading...
 
Back
Top