0

I have a button to update Record. When I press it 2 or 3 times in a row it gives me the following error:

System.Data.OleDb.OleDbException: 'Unspecified error'
ErrorCode -2147467259 Integer

the button calls an update routine as below

Public Sub UpdateREcord(ByVal lPartID As Long, ByVal sPartName As String,....im passing 60 variables) 

    Dim myConn As New OleDbConnection
    myConn = Provider.OleConnectDB

    Dim cmdUpdate As New OleDbCommand("Update EstParts ......all 60 fields  WHERE [PartID]=" & lPartID & "", myConn)

        cmdUpdate.ExecuteNonQuery()
        myConn.Close()

Is it because its a lot of fields? Is it because I press update several times in a row?

here is the connection string

Public Function OleConnectEstimateDB() As OleDbConnection
    Dim oleConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyDatabasePathAndName)
    If oleConn.State = ConnectionState.Closed Then oleConn.Open()
    Return oleConn
    oleConn.Close()
End Function

This error only happens if I press update several times in a row

dbc
  • 104,963
  • 20
  • 228
  • 340
  • 1
    Not sure but I don't think there is enough information in your question for us to answer successfully. Can you [edit] your question to share a full [mcve] as suggested in [ask]? – dbc Jun 23 '23 at 19:22
  • That being said, your method `OleConnectEstimateDB()` is strange: it opens the connection, returns it, then closes it **after the return.** Why do you do that? Should the returned connection be open, or closed? – dbc Jun 23 '23 at 19:24
  • 1
    Also, **Warning: your code is open to *SQL Injection Attacks***. Rather than embedding parameter values in query strings (e.g. `WHERE [PartID]=" & lPartID & ""`), you should **always** construct parameterized queries. See: [How do parameterized queries help against SQL injection?](https://stackoverflow.com/q/5468425/3744182) and [Why do we always prefer using parameters in SQL statements?](https://stackoverflow.com/q/7505808/3744182). – dbc Jun 23 '23 at 19:25
  • `-2147467259` is `80004005` in hex, so maybe see https://bobcares.com/blog/odbc-error-80004005/, [Microsoft OLE DB Provider for SQL Server error '80004005'](https://stackoverflow.com/q/15126625), or [DTS_E_OLEDBERROR. Error code: 0x80004005.Difference between SQl Native client and oledb provider for sql server](https://stackoverflow.com/q/21603897). – dbc Jun 23 '23 at 19:42

0 Answers0