Your installation must be broken. The code really does nothing vital, so there is no reason to hang it.
The SqlConnection constructor does the following:
public SqlConnection() { this.ObjectID = Interlocked.Increment(ref SqlConnection._objectTypeCount); base(); GC.SuppressFinalize(this); this._innerConnection = DbConnectionClosedNeverOpened.SingletonInstance; }
Thus, it increments the variable, copies it to the property, calls the base constructor, removes the object from the finalizer queue, and copies the link. It's all.
The base constructor ( DbConnection ) does the following:
protected DbConnection() { }
So, there is nothing here that actually is actually related to the actual connection to the database. All this is done when you really open the connection.
Your program may also hang after the first call to Console.WriteLine and may not even reach the SqlConnection creating an SqlConnection object.
source share