0

I get the given below error, when I connect localhost (docker - oracle-12.2.0.1) using Go. Same connection is working fine when I connect by table plus. Please suggest me to resolve this issue.

Reference

Code

conn, err := sql.Open("oracle", "oracle://SYS:Oradoc_db1@localhost/ORCLPDB1.localdomain")
if err != nil {
    fmt.Println("Can't open the driver", err)
    return
}

Error1

ORA-28009: connection as SYS should be as SYSDBA or SYSOPER

Code

conn, err := sql.Open("oracle", "oracle://SYSDBA:Oradoc_db1@localhost/ORCLPDB1.localdomain")
if err != nil {
    fmt.Println("Can't open the driver", err)
    return
}

Error2

ORA-01017: invalid username/password; logon denied
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Krish
  • 13
  • 2
  • I think the error is clear and it is not related to golang, try to check with username/password, maybe Case Sensitive issue or other you need to debug that – Manjeet Thakur Dec 22 '21 at 07:48
  • Let me check thanks @ManjeetThakur – Krish Dec 22 '21 at 07:50
  • User `sys` cannot connect to the Oracle DB "as is", because is is granted `sysdba` role. It should use special addition to its user name: `sys as sysdba`. See [Admin guide](https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/getting-started-with-database-administration.html#GUID-5F1E393E-97B8-43BC-BD68-3595251A6F7C) guide. You may check [similar question regarding java](https://stackoverflow.com/questions/10101517/how-to-connect-in-java-as-sys-to-oracle). – astentx Dec 22 '21 at 09:40
  • See Oracle DB connection examples in https://github.com/godror/godror/blob/main/doc/connection.md – Christopher Jones Dec 22 '21 at 21:55

1 Answers1

0

The username and password must be same as was specified in a GRANT CONNECT statement. And if you are entering the username and password together the format should be like this : username/password. Also check if they are case sensitive or not.

try this format :

 db, err := sql.Open("oracle", "<your username>/<your password>@service_name")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer db.Close()

OR

Also confirm golang oracle database driver

db, err := sql.Open("goracle", username+"/"+password+"@"+host+"/"+database)
if err != nil {
    fmt.Println("... DB Setup Failed") 
    fmt.Println(err)
    return
}
defer db.Close()
Ashutosh Singh
  • 721
  • 3
  • 6