以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]我需要操作数据库内的东西,但有时候数据库掉线了就会无响应,怎么写更好? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=161539) |
-- 作者:zto001 -- 发布时间:2021/3/21 20:13:00 -- [求助]我需要操作数据库内的东西,但有时候数据库掉线了就会无响应,怎么写更好? 这段代码是放在计划管理的,几秒执行一次,如果碰上数据库出问题,就直接卡死了。怎样写更好点并且保证效率质量? Try Dim id As Integer = DataTables("消息记录").Compute("Max(_Identify)") Dim Filter As String = "[_Identify] > " & id DataTables("消息记录").AppendLoad(Filter, False) Dim drs As List(Of DataRow) drs = DataTables("消息记录").Select("[_Identify] > " & id ) For Each dr As DataRow In drs \'解析快递订阅 Dim 问题类型,类型,接收者,发送者,群号,内容,单号,寄件人,快递 As String Dim 时间 As Date 时间=dr("接收时间") 类型=dr("消息类型") 接收者=dr("接收ID") 发送者=dr("发送ID") 群号=dr("群ID") 内容=dr("接收内容") If 内容.Contains("记账") Then Dim 收支,账本类型,账户,来源,接收内容,接收ID As String Dim 金额 As Single If 内容.Contains("收") Then 收支="收入" ElseIf 内容.Contains("付") Then 收支="支出" ElseIf 内容.Contains("支") Then 收支="支出" End If Dim s As String=内容 Dim p As String = "\\d+[\\.]?\\d*" Dim rgx = new System.Text.RegularExpressions.Regex(p, System.Text.RegularExpressions.RegexOptions.IgnoreCase) For Each m As object In rgx.Matches(s) 金额=m.value Next If 收支="支出" Then 金额= 金额*-1 End If Dim s1 As String=内容 Dim p1 As String = "(橙逸|嵩昭|苏营|宋良|梦梦|高世伟|易胜利|汪涛|任光明|林继成|罗森|杨剑|])" Dim rgx1 = new System.Text.RegularExpressions.Regex(p1, System.Text.RegularExpressions.RegexOptions.IgnoreCase) For Each m1 As object In rgx1.Matches(s1) 账户=m1.value Next Dim s2 As String=内容 Dim p2 As String = "(账单款|预付款|运输开支|报销开支|提成|返点|其他开销|])" Dim rgx2 = new System.Text.RegularExpressions.Regex(p2, System.Text.RegularExpressions.RegexOptions.IgnoreCase) For Each m2 As object In rgx2.Matches(s2) 账本类型=m2.value Next 来源="消息记录" If 收支="" OrElse 账本类型="" OrElse 金额 =Nothing OrElse 账户="" Then Else If 类型="群消息" Then 接收ID=群号 Else 接收ID=发送者 End If Dim cmd As new SQLCommand cmd.C cmd.CommandText = "Insert Into 账本 (收支, 类型 , 金额 ,账户 ,登记人 , 登记时间 ,来源,原始记录) Values(\'"& 收支 &"\',\'"& 账本类型 &"\',\'"& 金额 &"\',\'"& 账户 &"\',\'"& 发送者 &"\',\'" & 时间 &"\' ,\'"& 来源 &"\',\'"& 内容 &"\' )" cmd.ExecuteNonQuery 接收内容="【已记录】账本信息:" & "[" & 账户 & "]" & 收支 &"|"& 类型 & ";" & "¥" & 金额 & "|" & CUMoney(金额 ) & ";" & 发送者 & "|" & 来源 Dim cmd1 As new SQLCommand cmd1.C cmd1.CommandText = "Insert Into 发送记录 (应发时间,接收ID,接收内容,发送ID,群ID,消息类型,是否发送) Values(\'" & Date.Now &"\' ,\'"& 接收ID &"\',\'"& 接收内容 &"\',\'"& 接收者 &"\',\'"& 群号 &"\',\'"& 类型 &"\',\'false\' )" cmd1.ExecuteNonQuery End If 收支="" 账本类型="" 账户="" 来源="" 接收内容="" 金额=Nothing End If If 发送者="gh_bcf313592a63" AndAlso 内容.Contains("<?xml version=") Then Dim sps() As Char = { Chr(13),Chr(10),vbcrlf } Dim Values() As String = 内容.Split(sps) Dim hj As String = Values(8).Replace("
<des><![CDATA[","").Replace("最新动态","") Dim p As String = "[\\u4e00-\\u9fa5]" Dim rgx = new System.Text.RegularExpressions.Regex(p, System.Text.RegularExpressions.RegexOptions.IgnoreCase) For Each match As System.Text.RegularExpressions.Match In rgx.Matches(hj) Output.Show( match.Value) 快递=快递 & match.Value Output.Show( 快递) Next Output.Show(快递 & ":" & Values(8).Replace("
<des><![CDATA[","").Replace("最新动态","").Replace(快递 ,"") ) Output.Show( Values(10)) Output.Show(Values(12)) 快递="" End If Next Catch ex As Exception End Try |
-- 作者:有点蓝 -- 发布时间:2021/3/21 22:16:00 -- 没有什么好办法,保证数据库的正常运行才是最重要的。有钱可以考虑集群,没钱就把网络硬件搞好点吧 |
-- 作者:zto001 -- 发布时间:2021/3/22 21:09:00 -- 这是他本身的一个设定,会有断的情况。大概是十秒左右,有没有办法解决?比如连不上就不重连了,十秒后再试。之类的 |
-- 作者:有点蓝 -- 发布时间:2021/3/22 21:35:00 -- 没有办法 |