Error from the code RRS feed

  • Question

  • Hi

    we are facing the below issue while running some refresh jobs from console application by connecting to the SQL server.

    "The underlying connection was closed: A connection that was expected to be kept alive was closed by the server"

    Could you please help us to resolve this?



    Tuesday, August 20, 2019 12:47 PM

All replies

  • Hello,

    It's not possible to give a solution with limited information. What is needed, how are you connecting e.g. Entity Framework, managed data provider etc.

    For a managed data provider you should be using this pattern.

    public void Example()
        using (var cn = new SqlConnection {ConnectionString = "Your connection string"})
            using (var cmd = new SqlCommand {Connection = cn, CommandText = "Your statement"})
                // do some work
    Other reasons high traffic, and this.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    profile for Karen Payne on Stack Exchange

    Tuesday, August 20, 2019 1:14 PM
  • Hi Sunil A M, 

    Thank you for posting here.

    According to your description, I have two questions to confirm with you.

    Do you have the same problem in the link you give? Have you ever tried the solutions in the link?

    Besides, Could you provide some related code including which line of code throw the exception here? It will help us to analyze your problem.

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Wednesday, August 21, 2019 5:38 AM