调用新的SqlConnection()挂起程序 [英] calling new SqlConnection() hangs program

查看:137
本文介绍了调用新的SqlConnection()挂起程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这其中有我难住了。我还没有尝试连接到数据库。如果这个代码在那里我实例化一个新的SqlConnection对象行了,它只是挂在那儿,而不是抛出异常或任何东西。我试着编译它为2.0。 3.5和4.0,并且它们所有挂起。当然,它的作品在我的机器和你上了。但我试图运行在Windows Server 2008 x64的服务器上的代码,也不会让步。

This one has me stumped. I'm not even trying to connect to a database. When this code gets to the line where I instantiate a new SqlConnection object, it just hangs there, not throwing an exception or anything. I've tried compiling it for 2.0. 3.5 and 4.0, and they all hang. Of course it works on my machine and yours, too. But I'm trying to run this code on a Windows Server 2008 x64 server, and it won't budge.

// 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

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

推荐答案

这可能一个破碎的性能计数器这是问题。我有这个问题,我曾经将procmon检测发生了什么。当它来加载注册表项性能监视器.NET数据提供程序SqlServer的

It's probably a broken performance counter which is the issue. I had this problem and I used Procmon to detect what happened. My .NET application hanged when it came to loading the registry keys for the performance monitor ".NET Data Provider for SqlServer"

挂我的.NET应用程序卸载我用下面的命令计数器来获得它的工作:

I unloaded the counter with the following command to get it working:

unlodctr ".NET Data Provider for SqlServer"

这篇关于调用新的SqlConnection()挂起程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆