0

在连接到不同数据库的已打开程序中引发以下错误

向服务器发送请求时发生传输级错误。(提供者:TCP 提供者,错误:0 - 现有连接被远程主机强行关闭。)

程序详细信息:使用 vb.net 和 SQL Server 2008 作为后端完成的代码

同一 exe 的两个实例在同一台 PC 上同时运行但仅由一个实例引发错误

程序同时使用SqlConnection(ADO.NET)和ADODB连接(从 VB6 升级),两种类型的连接都会引发错误

如果错误是由于服务器的网络问题,那么为什么很少有程序可以正常工作?我无法追踪程序这种行为的原因

我可以知道为什么会发生此错误以及为什么仅在同一实例的少数程序中

4

2 回答 2

0

当您的 exe 的每个实例连接时,它都会获得自己的 SQL Server 进程 ID (SPID)。您收到错误是因为您的实例的连接在服务器级别被终止或在网络级别中断,在它尝试执行发生错误的 SQL 命令之前的某个时间点。

在 SSMS 中,检查您的 SQL Server 日志文件。在这个例子中,我杀死了一个 SPID,并记录了 SPID 的杀死: 在此处输入图像描述

如果您没有看到记录的事件,您可能正在处理网络问题。进一步的故障排除可能涉及在代码打开 ADODB 连接之后但出现错误之前的某处设置一个或多个断点,然后通过 SSMS 验证该实例的 SPID 是否在断点处运行。exec sp_who2是列出服务器上所有当前活动的 SPID 的好命令。

于 2012-05-19T13:22:42.470 回答
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
于 2017-05-25T05:26:55.090 回答