Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
My company has an SQL Server 7 legacy database installed on a Windows Server 2000 Advanced, the database is still used until this day and my company doesn't want to upgrade it for financial reasons, so I am asked to develop a web application that will retrieve and display certain data from it, and when I tried to debug it I got this error messagebox:

Quote:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)


I have tried so many things and a week of google searching didn't help me that much, please help me troubleshoot this issue, thank you in advance

What I have tried:

Backend code:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Data.Odbc;



namespace WebApp1
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            using (SqlConnection cnct = new SqlConnection("Server=x.x.x.x;User ID=xx;Password=xx;Database=xx;"))
            {
                try
                {
                    
                    cnct.Open();
                    
                    using (SqlCommand cmd = new SqlCommand("select codcli from client", cnct))
                    {
                        
                        SqlDataReader rdr = cmd.ExecuteReader();

                        
                        while (rdr.Read())
                        {
                            string code = rdr.GetString(1);
                        }

                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

            }

        }
    }
}



aspx page script:
ASP.NET
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApp1.Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    
        

    <asp:Repeater ID="repeater" runat="server">
        <HeaderTemplate>
            
        </HeaderTemplate>
        <itemtemplate>
            <table><tbody><tr class="Header">
                <td>Code</td>
            </tr><tr>
                <td>
                    <%# Eval("code") %>
                </td>
            </tr>
        
        
    
    </tbody></table>

 
</body>
</html>
Posted
Updated 24-Nov-16 1:51am
Comments
F-ES Sitecore 24-Nov-16 6:14am    
It's not your code, it's the SQL Server terminating the connection for some reason. Google the error message for possible reasons.
dali164 24-Nov-16 6:17am    
I googled it and the results didn't help me, I cam here as a last resort
F-ES Sitecore 24-Nov-16 6:50am    
There are loads of results for this issue

https://www.google.com/search?q=sql+server+A+connection+was+successfully+established+with+the+server%2C+but+then+an+error+occurred+during+the+pre-login+handshake

If you don't say which ones you've tried and what happened with them or in what way they didn't work then all people are going to do is suggest things you've already tried so to avoid wasting their time they are unlikely to answer. Try some of the solutions and update your question to indicate what didn't work and in what way it didn't work.
[no name] 24-Nov-16 7:11am    
It's not a code issue. Try asking a database administrator.
dali164 24-Nov-16 7:41am    
okay sorry

1 solution

This is a network or hardware issue - not a sql server (the software) issue, and certainly not applicable to c#.
 
Share this answer
 
Comments
dali164 24-Nov-16 9:42am    
do you have any link that can help me pin down the network or hardware issue?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900