Search code examples
asp.netenterprise-library

Count(*) using Enterprise Library


Does anyone have any idea how to use count(*) in a dynamic query with the Enterprise Library Data Access Application Block?

I am using:

Public Shared Function selectCount(ByVal code As String) As Integer
    Dim query As String = "SELECT COUNT(*) " & _
                          "FROM " & _
                            "Data " & _
                          "WHERE " & _
                            "Code = '" & code & "'"
    Dim db As Database = DatabaseFactory.CreateDatabase()
    Return db.ExecuteScalar(System.Data.CommandType.Text, query)
End Function

This error gets thrown:

The ITransactionLocal interface is not supported by the 'Microsoft.Jet.OLEDB.4.0' provider. Local transactions are unavailable with the current provider.


Solution

  • I looked up the error message and found that by adding "OLE DB Services=-4" to my connection string cleared up the problem while using the code above. So it seems my code was not technically wrong, just some problem with the connection string (although it was working fine before!)