Asp.net 对象引用未设置为MYSQLcommand上对象的实例

Asp.net 对象引用未设置为MYSQLcommand上对象的实例,asp.net,mysql,vb.net,Asp.net,Mysql,Vb.net,每隔几百次,我就会在生活网站上看到一个关于丢失物品的错误。 我一直在检查、测试、测试,但不知道出了什么问题。 有什么好主意吗 代码是: Dim MySqlCommand=New MySqlCommand(SQLC,MySqlConnect) 尝试 尝试=5次 lg&=“Co(” 做 Try:MySqlCommand.Connection.Open() 特例 lg&=“”&ex.消息 等待(0.5) 结束尝试 如果(MySqlCommand.Connection.State ConnectionS

每隔几百次,我就会在生活网站上看到一个关于丢失物品的错误。 我一直在检查、测试、测试,但不知道出了什么问题。 有什么好主意吗

代码是:

Dim MySqlCommand=New MySqlCommand(SQLC,MySqlConnect)
尝试
尝试=5次
lg&=“Co(”
做
Try:MySqlCommand.Connection.Open()
特例
lg&=“”&ex.消息
等待(0.5)
结束尝试
如果(MySqlCommand.Connection.State ConnectionState.Open),则尝试-=1
尝试>0和MySqlCommand.Connection.State ConnectionState.Open时循环
lg&=”“
特例
lg&=ex.message
结束尝试
lg&=''&LCase(左(SQLC,5))&“(Mc”
尝试
lg&=“En”:Dim ret=MySqlCommand.ExecuteNonQuery()
lg=“”
特例
lg&=“:”&ex.message
结束尝试
如果是lg“”,则响应写入(lg)
输出为:


Co()update(McEn:Object reference未设置为对象的实例。

使用.net日志框架,如.Log记录页面上发生的事情

根据我的经验,日志记录是捕获间歇性错误的最好方法

Dim MySqlCommand = New MySqlCommand(SQLC, MySqlConnect)
Try
   Tries = 5
   lg &= " Co("
   Do
       Try : MySqlCommand.Connection.Open()
       Catch ex As Exception
          lg &= " " & ex.Message 
          Wait(0.5) 
       End Try
       If (MySqlCommand.Connection.State <> ConnectionState.Open) Then Tries -= 1 
   Loop While Tries > 0 And MySqlCommand.Connection.State <> ConnectionState.Open
   lg &= ")"
Catch ex As Exception
   lg &= ex.message
End Try

lg &= " " & LCase(Left(SQLC, 5)) & "(Mc"

Try
    lg &= "En" : Dim ret = MySqlCommand.ExecuteNonQuery()
    lg = ""
Catch ex As Exception
   lg &= ":" & ex.message  
End Try

if lg<>"" then  Response.write(lg)