在已打开的程序中抛出以下错误,该程序连接到不同的数据库
将请求发送到服务器时发生传输级错误。 (提供者:TCP提供者,错误:0 - 现有连接 被远程主机强行关闭。)
程序详细信息:使用vb.net以SQL Server 2008作为后端完成的代码
两个同一个exe的实例同时在同一台PC上运行,但错误仅由一个实例抛出
程序使用SqlConnection
(ADO.NET)和ADODB
连接(从VB6升级),并且两种类型的连接都会引发错误
如果错误是由服务器的网络问题引起的,为什么很少有程序正常工作?我无法追踪程序的这种行为的原因
我能知道为什么会出现这种错误,为什么只能在同一实例的少数程序中出现
答案 0 :(得分:0)
当你的exe的每个实例连接时,它会获得自己的SQL Server进程ID(SPID)。您收到错误是因为实例的连接在服务器级别被终止或在网络级别被中断,在尝试执行发生错误的SQL命令之前的某个时刻。
在SSMS中,检查SQL Server日志文件。在这个例子中,我杀了一个SPID,并记录了杀死SPID:
如果您没有看到已记录的事件,则可能是在处理网络问题。进一步的故障排除可能涉及在打开ADODB连接之后但在错误之前在代码中设置一个或多个断点,然后通过SSMS验证该实例的SPID是否在断点处运行。 exec sp_who2
是列出服务器上所有当前活动SPID的好命令。
答案 1 :(得分: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