Why does connecting to Oracle Autonomous Database from golang fail?
php editor Baicao is here to answer a common question: "Why does the connection to the Oracle database from golang fail?" When using golang to connect to the Oracle database, sometimes the connection fails. question. This could be due to a variety of reasons, such as database misconfiguration, network connection issues, or driver incompatibility. This article will analyze the possible causes in detail and provide solutions to help readers solve this problem and make the process of connecting to the Oracle database smoother.
Question content
dsn := ` user=admin, password=temp1!a, (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-seoul-1.oraclecloud.com))(connect_data=(service_name=gee9edfb93f3cf6_redglqweyxqefhhf_high.adb.oraclecloud.com))(security=(ssl_server_cert_dn="cn=adb.ap-seoul-1.oraclecloud.com, ou=oracle adb seoul, o=oracle corporation, l=redwood city, st=california, c=us"))) ` db, err := sql.open("godror", dsn) if err != nil { fmt.println(err) return } defer db.close()
I created an autonomous database, I tried to connect with the above code in golang, but could not connect, the following error occurred, how to connect, I can't find a detailed manual, can you help me? p>
go run main.go parsing parameters "user=ADMIN,\n\tpassword=temp1!a,\n\t(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-seoul-1.oraclecloud.com))(connect_data=(service_name=gee9edfb93f3cf6_redglqweyxqefhhf_high.adb.oraclecloud.com))(security=(ssl_server_cert_dn=\"CN=adb.ap-seoul-1.oraclecloud.com, OU=Oracle ADB SEOUL, O=Oracle Corporation, L=Redwood City, ST=California, C=US\")))": logfmt syntax error at pos 44 on line 3: unexpected '='
Solution
I am a new user of oracle and golang, everything is new and I am having difficulty finding the documentation for connecting oracle and golang. There is a manual but I don't quite understand it.
If you post a question on stackoverflow, the answer is just a link to the manual. For beginners, it is really difficult to experience a new environment
I finally found the solution, my code is as follows. Even if you can't read the code, it's good to think about it one by one as you look at the examples.
package main import ( "database/sql" "fmt" go_ora "github.com/sijms/go-ora/v2" ) type DbInfo struct { Username string Password string } func main() { serverInfo := DbInfo{ Username: "databaseUser", Password: "databaseUserPassword", } urlOptions := map[string]string{ "TRACE FILE": "trace.log", "SSL VERIFY": "FALSE", } connectString := "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-seoul-1.oraclecloud.com))(connect_data=(service_name=gvsd1dfc9c3cdf6_racc7y8cxsvb16f0z_medium.adb.oraclecloud.com))(security=(ssl_server_dn_match=yes)))" db, err := sql.Open("oracle", go_ora.BuildJDBC(serverInfo.Username, serverInfo.Password, connectString, urlOptions)) if err != nil { panic(err.Error()) } defer db.Close() r, err := db.Exec(`create table users ( nickname varchar(20) )`) if err != nil { panic(err.Error()) } fmt.Println(r.LastInsertId()) }
The code above does not require a wallet for tls access. I will also upload below how to access it through the wallet for beginners who need it.
The above is the detailed content of Why does connecting to Oracle Autonomous Database from golang fail?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Yes, H5 page production is an important implementation method for front-end development, involving core technologies such as HTML, CSS and JavaScript. Developers build dynamic and powerful H5 pages by cleverly combining these technologies, such as using the <canvas> tag to draw graphics or using JavaScript to control interaction behavior.

How to use JavaScript or CSS to control the top and end of the page in the browser's printing settings. In the browser's printing settings, there is an option to control whether the display is...

Regarding the reasons and solutions for misaligned display of inline-block elements. When writing web page layout, we often encounter some seemingly strange display problems. Compare...

How to achieve the 45-degree curve effect of segmenter? In the process of implementing the segmenter, how to make the right border turn into a 45-degree curve when clicking the left button, and the point...

The method of customizing resize symbols in CSS is unified with background colors. In daily development, we often encounter situations where we need to customize user interface details, such as adjusting...

Compatibility issues of multi-row overflow on mobile terminal omitted on different devices When developing mobile applications using Vue 2.0, you often encounter the need to overflow text...

Real-time Bitcoin USD Price Factors that affect Bitcoin price Indicators for predicting future Bitcoin prices Here are some key information about the price of Bitcoin in 2018-2024:

Tips for Implementing Segmenter Effects In user interface design, segmenter is a common navigation element, especially in mobile applications and responsive web pages. ...
