c# - 调用 new SqlConnection() 挂起程序

标签 c# .net .net-2.0 sqlconnection

这个让我难住了。我什至没有尝试连接到数据库。当这段代码到达我实例化一个新的 SqlConnection 对象的行时,它只是卡在那里,没有抛出异常或任何东西。我试过为 2.0 编译它。 3.5和4.0,都挂了。当然它也适用于我的机器和你的机器。但我试图在 Windows Server 2008 x64 服务器上运行此代码,但它不会让步。

// example.cs
using System;
using System.Data;
using System.Data.SqlClient;

public class MainClass {
    public static void Main(string[] args) {
        Console.WriteLine("start");
        SqlConnection conn = new SqlConnection(); // hangs here
        Console.WriteLine("finish");              // never makes it here.
    }
}

编译(2.0): c:\Windows\Microsoft.NET\Framework\v2.0.50727\csc.exe example.cs

最佳答案

问题可能出在性能计数器损坏上。我遇到了这个问题,我使用 Procmon 来检测发生了什么。我的 .NET 应用程序在加载性能监视器“.NET Data Provider for SqlServer”的注册表项时挂起

我使用以下命令卸载了计数器以使其正常工作:

unlodctr ".NET Data Provider for SqlServer"

关于c# - 调用 new SqlConnection() 挂起程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8408236/

相关文章:

c# - 转换参数C#/SQL Server失败

c# - visual studio 删除文件中的所有断点

.net - “System.ComponentModel.DataAnnotations.dll”可用于 Android 和 iOS 吗?

c# - 如何为 .NET Core View 类替换 Request.Url.GetLeftPart(UriPartial.Authority)?

c# - ObjectDataSourceControl 无法在导入的命名空间中找到类型

C# DataGridViewLinkCell 显示

c# - Linq2SQL 表达式没有翻译的解决方案

c# - 将静态方法附加到类而不是类实例的最佳方法是什么?

c# - 调用 Dispose() 后图标仍然可用吗?

c# - CurrentCellDirtyStateChanged 提交得太早