Search code examples
vb.netoracleodp.net

Increment column value by one in Oracle - (ORA-01013)


I have the following update statement which works fine in SQL Developer:

UPDATE SDUSERS SET PWDATTEMPTS=PWDATTEMPTS+1 WHERE lower(UserName)='test';

Now, in my VB.NET it does not update the database for some reason and it produces error ORA-01013: user requested cancel of current operation, Error code: -2147467259

Dim sqlUpdateFailed As New OracleCommand("UPDATE " & oConnection.SCHEMA_NAME.ToUpper 
 & "SDUSERS SET PWDATTEMPTS=PWDATTEMPTS+1 WHERE lower(USERNAME)='" & sUsername & "'", conn)
                sqlUpdateFailed.CommandTimeout = 20
                sqlUpdateFailed.ExecuteNonQuery()

Any ideas what I might be doing wrong?


Solution

  • Most likely, reason of ORA-1013 in your case is a query execution timeout reached. Check it, try some big timeout value.

    Such update should be executed fast, very fast (I guess table is small, isn't it?) So if it's hang it means the record is locked. Maybe you updated this record into SQL Developer and forgot to commit, maybe something else. You can check it if execute something like SELECT * FROM SDUSERS WHERE lower(UserName) = :username FOR UPDATE NOWAIT before your update statement.

    BTW, your source gives an excellent ability for SQL Injection.