I have created a simple oracle table that I'm trying to connect to VB.net
I'm able to connect but I can't add any record to the table. I'm receiving the message: ORA-00903: Invalid table name.
Here's the preview screen of my Oracle Database Manager from which I created the table.
Oracle Enterprise Manager screenshot (Sorry it's in french)
Here is the code I'm using:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Oracle = New OracleObject("192.128.7.15", 1521, "TechnicalDatabase", "system", "admin")
If Oracle.Connect = False Then
Exit Sub
End If
Dim Sql As String
Sql = "INSERT INTO USER (ID, FirstName) values ('1','Jim');"
Oracle.ExecuteSubQuery(Sql)
Oracle.Disconnect()
End Sub
Public Function ExecuteSubQuery(ByVal SQL As String) As Boolean
Dim Command As New OracleCommand(SQL, Connection)
Command.CommandType = CommandType.Text
Try
Command.ExecuteReader()
Catch ex As Exception
MsgBox("Error in query !" & Chr(13) & ex.Message)
Return False
End Try
Return True
End Function
Thanks.
SYSTEM
but the table is owned byCOLMANTECHNICALADMIN
. Assuming that you haven't created a synonym in theSYSTEM
schema and that you're not doing anALTER SESSION SET current_schema=COLMANTECHNICALADMIN
, you would need to fully qualify the table name.USER
is a reserved word. If you really, really, really want to use a reserved word as a table name, you would need to enclose it in double quotes every time you reference it and ensure that you are always capitalizing the name correctly. It would generally be much better to choose a name that did not collide with a reserved word. But, if you insist on doing so, your query would need to beINSERT INTO COLMANTECHNICALADMIN."USER" (ID, FirstName) values ('1','Jim');
You should not be connecting to the database as either
SYS
orSYSTEM
. Your applications should be using some application-specific account that you have created that has whatever privileges the application needs.Thank you guys for you answers.
Here is my final solution:
Remark: When I tried to execute the query with a semicolumn at the end, I got an error message: ORA00911: Invalid Character. So I had to remove it.
Thanks for your help.
USER
is an Oracle reserved word. You have two choices:Use a different table name (for example
USERS
orUSER_LIST
).Put the name in double quotes. If you do this, the table name also becomes case-sensitive, which can lead to a lot of "gotchas". I'd recommend using a different table name.
Try replacing ExecuteReader with ExecuteNonQuery
However your primary problem is the word USER that is a reserved keyword as
Ed Gibbs
has correctly written in its answer (And given reasonable workarounds)