I am new to Go with Oracle SQL DB connection, I just created a Go project and setting up for it to connect to my Oracle DB, below are some of the info of my setup, and what I have tried to troubleshoot.
- Ubuntu 22 WSL
- installed Oracle instant client
- tested connection with SQLplus
- still hitting below error when “go run main.go”
github.com/godror/godror ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:563:19: undefined: VersionInfo ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:564:19: undefined: VersionInfo ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:565:10: undefined: StartupMode ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:566:11: undefined: ShutdownMode ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:568:31: undefined: Event ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:568:42: undefined: SubscriptionOption ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:568:64: undefined: Subscription ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:569:31: undefined: ObjectType ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:570:59: undefined: Data ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:571:28: undefined: DirectLob ../../go/pkg/mod/github.com/godror/[email protected]/orahlp.go:571:28: too many errors
main.go content as below:
package main
import (
"database/sql"
"fmt"
"log"
_ "github.com/godror/godror"
)
func main() {
db, err := sql.Open("godror", `user="user" password="password" connectString="(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=<ip-address>)(Port=1521))(CONNECT_DATA=(SID=<sid>)))"
libDir="/opt/oracle/instantclient_23_5"`)
if err != nil {
log.Fatalf("Failed to open connection: %v", err)
}
defer db.Close()
// Ping the database to verify the connection
err = db.Ping()
if err != nil {
log.Fatalf("Failed to connect to the database: %v", err)
}
fmt.Println("Successfully connected to Oracle Database!")
}
2
reference: https://github.com/godror/godror/issues/115
Need to make sure you have a working C compiler installed on your system to build and run Go applications that use godror
for Ubuntu 22:
Step 1: Install a C Compiler
The most common C compiler used with Go is gcc. You can install it along with other essential build tools using the following command:
sudo apt update
sudo apt install build-essential
This will install gcc, g++, make, and other essential tools needed to compile C programs.
Step 2: Verify Installation
You can verify that gcc is installed correctly by checking its version:
gcc --version