I was tried like so:
using System;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Trace;
namespace SqlProfiller
{
public partial class Form1 : Form
{
TraceServer reader = new TraceServer();
SqlConnectionInfo connInfo = new SqlConnectionInfo();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
connInfo.ServerName = @".\SQLR2";
connInfo.DatabaseName = "DB";
connInfo.UserName = "sa";
connInfo.Password = "123";
reader.InitializeAsReader(connInfo, @"Standard.tdf");
while (reader.Read())
{
Console.WriteLine("SPID : " + reader["SPID"]);
Console.WriteLine("Login : " + reader["SessionLoginName"]);
Console.WriteLine("Object: " + reader["ObjectName"]);
Console.WriteLine("Text : " + reader["TextData"]);
Console.WriteLine();
textBox1.Text += "Event : " + reader["EventClass"] + Environment.NewLine;
textBox1.Text += "SPID : " + reader["SPID"] + Environment.NewLine;
textBox1.Text += "Login : " + reader["SessionLoginName"] + Environment.NewLine;
textBox1.Text += "Object: " + reader["ObjectName"] + Environment.NewLine;
textBox1.Text += "Text : " + reader["TextData"] + Environment.NewLine;
textBox1.Text += "----------------------------------------------------------";
textBox1.Text += Environment.NewLine;
Application.DoEvents();
}
}
}
}
Error:
Microsoft.SqlServer.Management.Trace.SqlTraceException: Failed to initialize object as reader. ---> System.IO.FileLoadException: Mixed mode assembly is built against version 'v2.0.50727' of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.
Failed to initialize object as reader.
What does this mean?
Thanks in advance