我被这样尝试过:
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();
}
}
}
}
错误:
Microsoft.SqlServer.Management.Trace.SqlTraceException:无法将对象初始化为读取器。---> System.IO.FileLoadException:混合模式程序集是针对运行时版本“v2.0.50727”构建的,如果没有额外的配置信息,则无法在 4.0 运行时中加载。
无法将对象初始化为读取器。
这是什么意思?
提前致谢