我正在使用一种显示DataBase Content As Json Arrays的方法。有些时候它有效但是很多次它给了我这个错误:
超时已过期。在获得a之前经过了超时时间 从游泳池连接。这可能是因为所有人都集中了 正在使用连接并达到最大池大小
顺便说一下其他方法的效果很好但是这个方法就是这样做的
这是WebMethod代码:
<WebMethod>
Public Sub AfterOrdersInsert(JSONString As [String])
Try
Dim context As HttpContext = Me.Context
Dim strJson As String = ""
Dim OrderItems As JArray = JArray.Parse(JSONString)
'Dim IncrementalConnection As New SqlConnection()
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("MyCString").ConnectionString)
For Each OrderItem As JObject In OrderItems
conn.Open()
Dim SelectQuery As String = "SELECT * FROM Orders WHERE OrderId = @a AND Name = @b"
Dim SelectCommand As New SqlCommand(SelectQuery, conn)
SelectCommand.Parameters.AddWithValue("@a", OrderItem.Item("OrderId").ToString())
SelectCommand.Parameters.AddWithValue("@b", OrderItem.Item("Name").ToString())
Dim reader = SelectCommand.ExecuteReader()
Dim isExist = reader.HasRows
Dim OrderQuantity As Integer = 0
If isExist Then
reader.Read()
OrderQuantity = Convert.ToInt32(reader.GetString(reader.GetOrdinal("ProductQuantity"))) + Convert.ToInt32(OrderItem.Item("ProductQuantity").ToString())
End If
conn.Close()
'Using reader = SelectCommand.ExecuteReader()
If isExist Then
'If reader.Read() Then
conn.Open()
Dim Price = OrderQuantity * Convert.ToDouble(OrderItem.Item("Price").ToString())
Dim UpdateQuery As String = "UPDATE Orders SET ProductQuantity = @c, Price = @d WHERE OrderId = @e AND Name = @f"
Dim UpdateCommand As New SqlCommand(UpdateQuery, conn)
UpdateCommand.Parameters.AddWithValue("@c", OrderQuantity.ToString())
UpdateCommand.Parameters.AddWithValue("@d", Price.ToString())
UpdateCommand.Parameters.AddWithValue("@e", OrderItem.Item("OrderId").ToString())
UpdateCommand.Parameters.AddWithValue("@f", OrderItem.Item("Name").ToString())
UpdateCommand.ExecuteNonQuery()
conn.Close()
Else
Dim strSQL As String = "insert into Orders(ProductNumber,Name,Category,Price,OrderId,TableNumber,WaiterName,CashierName,DateAndTime,isActive,isCoocked,isPaid,isYesCanceled,ProductQuantity) values(@x,@y,@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l)"
conn.Open()
Dim cmd As New SqlCommand(strSQL, conn)
cmd.Parameters.AddWithValue("@x", OrderItem.Item("ProductNumber").ToString())
cmd.Parameters.AddWithValue("@y", OrderItem.Item("Name").ToString())
cmd.Parameters.AddWithValue("@a", OrderItem.Item("Category").ToString())
cmd.Parameters.AddWithValue("@b", Convert.ToDouble(OrderItem.Item("Price").ToString()) * Convert.ToInt32(OrderItem.Item("ProductQuantity").ToString()))
cmd.Parameters.AddWithValue("@c", OrderItem.Item("OrderId").ToString())
cmd.Parameters.AddWithValue("@d", OrderItem.Item("TableNumber").ToString())
cmd.Parameters.AddWithValue("@e", OrderItem.Item("WaiterName").ToString())
cmd.Parameters.AddWithValue("@f", OrderItem.Item("CashierName").ToString())
cmd.Parameters.AddWithValue("@g", OrderItem.Item("DateAndTime").ToString())
cmd.Parameters.AddWithValue("@h", OrderItem.Item("isActive").ToString())
cmd.Parameters.AddWithValue("@i", OrderItem.Item("isCoocked").ToString())
cmd.Parameters.AddWithValue("@j", OrderItem.Item("isPaid").ToString())
cmd.Parameters.AddWithValue("@k", OrderItem.Item("isYesCanceled").ToString())
cmd.Parameters.AddWithValue("@l", OrderItem.Item("ProductQuantity").ToString())
cmd.ExecuteNonQuery()
conn.Close()
End If
'End Using
Next
'ProductNumber As [String], Name As [String], Category As [String], Price As [String], OrderId As [String]'
'this is the bridge to database\
strJson = "{" + "" + "contact" + "" + ":" + "[" + "{" + "result" + "" + ":" + serializer.Serialize("1") + "}" + "]" + "}"
context.Response.Write(strJson)
Catch ex As Exception
Dim strJson As String
strJson = "{" + "" + "contact" + "" + ":" + "[" + "{" + "result" + "" + ":" + serializer.Serialize("0") + ex.Message + "}" + "]" + "}"
Context.Response.Write(strJson)
End Try
End Sub