none
exe that has one line of code pauses on this line: return new SqlConnection() RRS feed

  • Question

  • I have created an exe in my attempt to track down why a program just pauses. The code is basically this. In a console application there is one line of code which calls a method: private SqlConnection GetConnection(){ try{ Console.WriteLine("Start"); return new SqlConnection(); }finally{ Console.WriteLine("End"); } } If I execute this program the application stops. I put a Console.WriteLine() before and after the return statement. Only the first Console.WriteLine() shows. The application never stops running. What I see in the console output is "Start". That's it. The application stays in the taskmanager processes tab too and the console window stays open. This is on Windows Server 2008.
    • Edited by Stumple Tuesday, December 6, 2011 9:46 PM changed stop to pause
    Tuesday, December 6, 2011 9:46 PM

Answers

  • We uninstalled and then installed .NET again. Then we rebooted the server.

     

    It works now.

    • Marked as answer by Stumple Tuesday, December 20, 2011 2:29 PM
    Tuesday, December 20, 2011 2:29 PM

All replies

  • Hi Stumple,

    Welcome!

    I'm not very sure about your question. The finally will always run in GetConnection method.

    My suggestion is using one connection one Command. You can refer this link: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx. use "using" to wrap each SqlConnection.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, December 7, 2011 8:23 AM
    Moderator
  • The problem is the finally NEVER ever runs. It should by reading the code. The executable, when run, comes to a pause at the return line. The CLR is trying to create a SQLConnection and it seems like it just doesn't know what to do and it HANGS.

     

    I think this error would be very rare. I am just trying to find someone that has come across it.

    Wednesday, December 7, 2011 2:36 PM
  • Hi Stumple,

    It's very strange. Would you please clarify your scenarios. In console application it should work as expected, are you just debuging and stop it at the reture code, the finally won't be ran. Thanks for your understanding.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 13, 2011 9:04 AM
    Moderator
  • Hi,

    I am writing to check the status of the issue on your side. Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know. I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, December 19, 2011 3:42 AM
    Moderator
  • We uninstalled and then installed .NET again. Then we rebooted the server.

     

    It works now.

    • Marked as answer by Stumple Tuesday, December 20, 2011 2:29 PM
    Tuesday, December 20, 2011 2:29 PM