I ve written a console app in VB. 该网络从事一些数据库工作,并出现奇怪的运行时间错误。
The main Code:
Sub Main(ByVal args() As String)
Try
user = args(0)
batchID = args(1)
GetBatchRevision()
batchRev = 1
Dim getTestScripts As SqlCommand = New SqlCommand("GetTestScriptsInTestBatch", cs)
getTestScripts.CommandType = CommandType.StoredProcedure
Dim batchIDParam As SqlParameter = getTestScripts.Parameters.Add("@batchID", SqlDbType.Int, 4)
Dim batchRevParam As SqlParameter = getTestScripts.Parameters.Add("@batchRev", SqlDbType.Int, 4)
batchIDParam.Value = 1
batchRevParam.Value = 1
batchIDParam.Value = batchID
batchRevParam.Value = batchRev
Console.WriteLine(batchID & " " & batchRev)
Console.WriteLine(cs.State)
Console.ReadLine()
Using cs
cs.Open()
Dim reader As SqlDataReader = getTestScripts.ExecuteReader(CommandBehavior.CloseConnection)
While reader.Read()
Console.WriteLine("Executing Test Script " & reader("ScriptID").ToString() & " Revision " & reader("ScriptRev").ToString)
End While
Console.ReadLine()
End Using
Catch ex As Exception
End Try
End Sub
GetBatchRevision:
Private Sub GetBatchRevision()
Using cs
Dim GetNewestRev As New SqlCommand("SELECT Max(BatchRev) FROM TestBatch WHERE BatchID=" & batchID, cs)
cs.Open()
Dim reader As SqlDataReader = GetNewestRev.ExecuteReader(CommandBehavior.CloseConnection)
reader.Read()
If Not IsDBNull(reader(0)) Then
batchRev = reader(0).ToString()
End If
End Using
End Sub
<代码>batchRev和batchID
均为该模块内的全球变量。
突然:
- The app prints out "1" (user input), "1" (database result), "0" (enum of Closed connection)
- When I press Enter to get past the first
Console.ReadLine()
, the app simply closes out.
如果我发表以下意见:GetBatchRevision
,并直接设定batchRev = 1
,则我得出上述结果,以及“Executing Test 1 Revision 52”,“Executing Test cast 2 Revision 66”,这些结果是所储存程序的结果。 《在试验中的试验》(
)。
全球变化宣言如下:
<条码> ID As String
<条码> Rev As String
任何想法,为什么