gpt4 book ai didi

c# - 如何接收 SQL Server 事件探查器事件?

转载 作者:太空狗 更新时间:2023-10-30 00:33:25 26 4
gpt4 key购买 nike

我是这样试过的:

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: 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.

无法将对象初始化为读取器。

这是什么意思?

提前致谢

最佳答案

这是什么意思?

System.IO.FileLoadException:混合模式程序集是针对运行时版本“v2.0.50727”构建的,如果没有附加配置信息,则无法在 4.0 运行时中加载。

这意味着您的进程作为 .NET 4 进程运行,并且您正在加载的程序集是 .NET 2 编译的(Microsoft.SqlServer.Management)。

重新编译您的应用程序以使用 .NET 2 或 add a hint for .NET 4 in config允许 .NET 2 程序集。

关于c# - 如何接收 SQL Server 事件探查器事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11987341/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com