2012-05-19 89 views
0

下面的錯誤被拋出在已經打開的程序,它連接到不同的數據庫SQL Server連接相關的錯誤

A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

計劃的細節:用vb.net與SQL Server 2008作爲後端代碼進行

同樣的EXE的兩個實例,其中在同一臺PC上,但錯誤同時運行是由一個實例只拋出

計劃同時使用SqlConnection(ADO.NET)和ADODB連接(從VB6升級)和錯誤是由兩種類型的connectio拋出n

如果錯誤是由於服務器的網絡問題,爲什麼很少的程序工作正常?我無法追查原因行爲的程序

我能知道爲什麼會出現這個錯誤,爲什麼只有在同一個實例

回答

0

的幾個節目當你的exe文件的每個實例連接,它得到了自己SQL Server進程ID(SPID)。您正在接收錯誤,因爲您的實例連接在服務器級別被終止或在網絡級別中斷,在嘗試執行發生錯誤的SQL命令之前的某個時間點。

在SSMS中,檢查您的SQL Server日誌文件。在這個例子中,我殺死了一個SPID,並且記錄了SPID的殺戮: enter image description here

如果您沒有看到記錄的事件,那麼您可能是在處理網絡問題。進一步的故障排除可能涉及在代碼打開ADODB連接之後,但在出現錯誤之前在代碼中設置一個或多個斷點,然後通過SSMS驗證該實例的SPID是否在斷點處運行。 exec sp_who2是列出服務器上當前所有活動SPID的好命令。

0
Imports System.Data 
Imports System.Data.SqlClient 


Public Class Form2 



Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

End Sub 
Private Function call_add() 

    Dim tam, eng, mat, sci, soc, tot As Decimal 
    tam = 0 
    eng = 0 
    mat = 0 
    sci = 0 
    soc = 0 
    tot = 0 
    If tamil.Text <> "" Then 
     tam = Convert.ToDecimal(tamil.Text) 
    End If 
    If english.Text <> "" Then 
     eng = Convert.ToDecimal(english.Text) 
    End If 

    If maths.Text <> "" Then 
     mat = Convert.ToDecimal(maths.Text) 
    End If 

    If science.Text <> "" Then 
     sci = Convert.ToDecimal(science.Text) 
    End If 

    If social.Text <> "" Then 
     soc = Convert.ToDecimal(social.Text) 
    End If 

    tot = tam + eng + mat + sci + soc 
    total.Text = tot.ToString 
    percentage.Text = total.Text/500 * 100 

    Return False 
End Function 

Private Sub total_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles total.TextChanged 
    call_add() 
End Sub 

Private Sub percentage_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles percentage.TextChanged 
    call_add() 

End Sub 

Private Sub tamil_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tamil.TextChanged 
    call_add() 

End Sub 

Private Sub english_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles english.TextChanged 
    call_add() 

End Sub 

Private Sub maths_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles maths.TextChanged 
    call_add() 

End Sub 

Private Sub science_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles science.TextChanged 
    call_add() 

End Sub 

Private Sub social_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles social.TextChanged 
    call_add() 

End Sub 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    Dim con As SqlConnection 
    Dim cmd As SqlCommand 
    'Dim str As String 
    con = New SqlConnection("server=WHITE-PC\WHITEPC;initial catalog=markreg;Integrated Security=True") 
    cmd = New SqlCommand 
    con.Open() 
    Dim command As New SqlCommand 
    cmd.Connection = con 
    command = New SqlCommand("stdregno,stdname,tamil,english,maths,science,social,total,percentage", con) 
    command.ExecuteNonQuery() 
    con.Close() 
    MsgBox("Added Sucessfully", MsgBoxStyle.Information, "Succesfully") 
    call_clear() 
End Sub 
Private Function call_clear() 

    stdregno.Text = "" 
    stdname.Text = "" 
    tamil.Text = "" 
    english.Text = "" 
    maths.Text = "" 
    science.Text = "" 
    social.Text = "" 
    total.Text = "" 
    percentage.Text = "" 
End Function 


Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 
    Form1.Show() 
    Me.Hide() 
End Sub 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
    InputBox("Enter the Regno You want search") 

End Sub 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 
    InputBox("Enter the Regno You want Modify") 
End Sub 

End Class 
+0

歡迎來到SO。請閱讀[如何解答](http://stackoverflow.com/help/how-to-answer),並正確地格式化代碼。 – thewaywewere