后端发送无法识别的响应类型:u错误与Postgres 9.3和npgsql

时间:2014-02-06 00:54:38

标签: postgresql npgsql

我昨天将我的服务器从Postgres 9.1升级到9.3,从那以后我收到了一个错误:后端发送了无法识别的响应类型:u

我正在使用npgsql从我的应用程序连接到服务器。

我记得我过去曾经有过这个错误,而且我有一段时间没有看到它。

我的日志中的完整行是:

Backend sent unrecognized response type: u
INSERT INTO stockcodes_rating (item_code,rating,price_range,user_id,timestamp_of_rating) VALUES ('10245684','5','Reasonable','10832',now())

我的程序代码是:

Public Function InsertRating(ByVal Stockcode As String, ByVal Rating As Integer, ByVal PriceRange As String, ByVal UserId As String) As String

    Dim objDBWrite As dlNpgSQL
    objDBWrite = New dlNpgSQL("PostgreConnectionStringWrite", ConfigurationManager.AppSettings("CurrentDatabase"))

    tmpSQL = "INSERT INTO stockcodes_rating (item_code,rating,price_range,user_id,timestamp_of_rating) VALUES " & _
            "('" & Stockcode.ToUpper & "','" & Rating & "','" & PriceRange & "','" & UserId & "',now())"
    Try
        objDBWrite.ExecuteQuery(tmpSQL)
    Catch ex As Exception
        objDBWrite.CloseConnection()
        Return ex.Message
    Finally
        objDBWrite.CloseConnection()
    End Try

    Return "Success"

End Function

我的dlNpgSQLclass代码是:

导入Npgsql

公共类dlNpgSQL     Dim _sqlConnection作为NpgsqlConnection     Dim _sqlCommand As NpgsqlCommand     Dim _sqlDataAdapter As NpgsqlDataAdapter     Dim _dataset As DataSet

Public Sub New()
    On Error GoTo ErrZ
    _sqlConnection = New NpgsqlConnection(ConfigurationManager.ConnectionStrings("PostgreRemoteConnectionString").ConnectionString)

    Exit Sub

End Sub

Public Sub New(ByVal WhichConnectionString As String)
    On Error GoTo ErrZ
    _sqlConnection = New NpgsqlConnection(ConfigurationManager.ConnectionStrings(WhichConnectionString).ConnectionString)

    Exit Sub
End Sub

Public Sub New(ByVal WhichConnectionString As String, ByVal WhichDB As String)
    On Error GoTo ErrZ
    _sqlConnection = New NpgsqlConnection(ConfigurationManager.ConnectionStrings(WhichConnectionString).ConnectionString & "database=" & WhichDB & ";")

    Exit Sub
End Sub

Public Function OpenConnection() As NpgsqlConnection

    Try
        If _sqlConnection.State = ConnectionState.Closed Then
            _sqlConnection.Open()
        End If
    Catch ex As Exception
    End Try
    Return _sqlConnection
End Function

Public Sub CloseConnection()

    Try
        If _sqlConnection.State = ConnectionState.Open Then
            _sqlConnection.Close()
        End If
    Catch ex As Exception
    End Try

End Sub

Public Function GetDataSet(ByVal strQuery As String) As DataSet

    'NpgsqlEventLog.Level = LogLevel.Normal
    'NpgsqlEventLog.LogName = ("c:\npgsql.log")
    'NpgsqlEventLog.EchoMessages = True

    _dataset = New DataSet

    Try
        _sqlDataAdapter = New NpgsqlDataAdapter(strQuery, OpenConnection)
        _sqlDataAdapter.Fill(_dataset)
    Catch ex As Exception
    End Try

    Return _dataset

End Function

Public Function ReleaseDataSet(ByRef ds As DataSet) As Boolean
    Try
        ds.Clear()
        ds.Dispose()
    Catch ex As Exception
    End Try
    Return True
End Function

Public Function ExecuteQuery(ByVal strQuery As String) As String

    'NpgsqlEventLog.Level = LogLevel.Normal
    'NpgsqlEventLog.LogName = ("c:\npgsql.log")
    'NpgsqlEventLog.EchoMessages = True
    Dim RecordsReturned As String = ""

    Try
        _sqlCommand = New NpgsqlCommand(strQuery, OpenConnection)
        RecordsReturned = _sqlCommand.ExecuteNonQuery()
    Catch ex As Exception
        Return ""
    End Try

    Return RecordsReturned

End Function

Public Function isR(ByVal tmpDs As DataSet, Optional ByVal tablename As Integer = 0) As Boolean
    Try
        If tmpDs.Tables.Count > 0 Then
            If tmpDs.Tables(0).Rows.Count > 0 Then
                isR = True
            Else
                isR = False
            End If
        End If
    Catch ex As Exception
        isR = False
    End Try
End Function

结束班

2 个答案:

答案 0 :(得分:1)

您使用的是什么版本的npgsql?您可能需要升级到2.0.14.3。

更好的是,尝试2.1.0-beta1,它非常稳定,即将发布。

答案 1 :(得分:0)

同样的事情发生在我身上使用Npgsql 2.0.12.0共享线程之间的连接。在每个线程中建立新连接是解决方案!