我正在查询一个外部数据库,它会引发以下错误:
ERROR: 25006: cannot execute UNLISTEN during recovery
我的理解是,postgreSQL 每次完成都会调用这个,这表明这是由关闭连接引起的。
对我来说奇怪的是,代码似乎可以打开与数据库的连接,但在尝试关闭连接时出错。此外,这似乎只是偶尔发生,所以这可能是由于数据库本身重新启动吗?
postgreSQL 如何打开一个连接,但不能关闭一个?
下面是执行的代码,麻烦的行是 dbConn.Close()
Dim sConnectionString as String = "Server=10.2.21.46;Port=5432;User Id=myuser;Password=mypsw;Database=demos;"
Dim sErrorMessage As String = ""
Dim bConnectionOpen As Boolean = False
Dim dbConn As Npgsql.NpgsqlConnection = New Npgsql.NpgsqlConnection(sConnectionString)
Try
dbConn.Open()
bConnectionOpen = True
Catch
sErrorMessage = "open connection fail."
End Try
If bConnectionOpen Then
Dim cmdTxt As String = sQueryString
Dim cmdTmp As Npgsql.NpgsqlCommand = New Npgsql.NpgsqlCommand(cmdTxt, dbConn)
Dim bReaderOpen As Boolean = False
Dim rsTmp As Npgsql.NpgsqlDataReader
Try
rsTmp = cmdTmp.ExecuteReader()
bReaderOpen = True
Catch
sErrorMessage = "ExecuteReader fail."
End Try
If bReaderOpen Then rsTmp.Close()
rsTmp = Nothing
dbConn.Close()
End If