sijms / go-ora

Pure go oracle client
MIT License
796 stars 177 forks source link

Getting EOF Error while pinging database connection with password having secial character '@' #491

Closed avinashvvm closed 9 months ago

avinashvvm commented 9 months ago

Seems that password which contains special character @ giving below error. Kindly let us know the fix.

We have refered previous posts of special characters. However it doesnt help much.

package main

import (
    "database/sql"
    "fmt"

    go_ora "github.com/sijms/go-ora/v2"
)

func connect(host string, username string, password string, port int) (*sql.DB, error) {

    serviceName := "ORACLE"

    urlOptions := map[string]string{
        "TRACE FILE": "Trace.log",
    }

    connStr := go_ora.BuildUrl(host, port, serviceName, username, password, urlOptions)
    fmt.Printf("Opening connection to db using go-ora: %v", connStr)

    // Connect to the database
    Connection, err := sql.Open("oracle", connStr)
    if err != nil {
        fmt.Println("Unable to open connection : " + err.Error())
        return nil, err
    }

    // Test the connection
    err = Connection.Ping()
    if err != nil {
        fmt.Println("Ping Failed : " + err.Error())
        Connection.Close()
        return nil, err
    }

}

func main() {
    user := "XXXXX"
    host := "XXXX.XXXXXX.com"
    port := XXXXX
    pwd := "ABCD@1234"

    _, err := connect(host, user, pwd, port)
    if err != nil {
        fmt.Println(err.Error)
    }
}

Output:

Ping Failed : EOF

sijms commented 9 months ago

Hi @avinashvvm EOF is not because of password. may be your connection using TCPS also you can confirm that by using trace file url option

avinashvvm commented 9 months ago

Here is my trace file which shows protocol as tcp. Can you please tell us how this can be fixed or make corrections in the above mentioned code?

2023-12-27T12:05:17.2055: Connect
2023-12-27T12:05:17.2091: using: XXXX.XXXXXX.com:XXXXX ..... [SUCCEED]
2023-12-27T12:05:17.2092: Open :(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=XXXX.XXXXXX.com)(PORT=XXXX))(CONNECT_DATA=(SERVICE_NAME=ORACLE)(CID=(PROGRAM=./oracletest)(HOST=XXXX)(USER=XXXX))))
2023-12-27T12:05:17.2092:
Write packet:
00000000  00 fb 00 00 01 00 00 00  01 3d 01 2c 0c 01 ff ff  |.........=.,....|
00000010  ff ff 4f 98 00 00 00 01  00 b5 00 46 00 00 00 00  |..O........F....|
00000020  01 01 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 20 00 00 00 20  |........... ... |
00000040  00 00 00 00 00 00 28 44  45 53 43 52 49 50 54 49  |......(DESCRIPTI|
00000050  4f 4e 3d 28 41 44 44 52  45 53 53 3d 28 50 52 4f  |ON=(ADDRESS=(PRO|
00000060  54 4f 43 4f 4c 3d 74 63  70 29 28 48 4f 53 54 3d  |TOCOL=tcp)(HOST=|
00000070  64 62 39 37 2e 6b 6f 74  61 6b 73 65 63 6f 6e 6c  |XXXX.XXXXXXXXXXX|
00000080  69 6e 65 2e 63 6f 6d 29  28 50 4f 52 54 3d 34 31  |XXX.com)(PORT=XX|
00000090  30 30 35 29 29 28 43 4f  4e 4e 45 43 54 5f 44 41  |XXX))(CONNECT_DA|
000000a0  54 41 3d 28 53 45 52 56  49 43 45 5f 4e 41 4d 45  |TA=(SERVICE_NAME|
000000b0  3d 4f 52 41 43 4c 45 29  28 43 49 44 3d 28 50 52  |=ORACLE)(CID=(PR|
000000c0  4f 47 52 41 4d 3d 2e 2f  6f 72 61 63 6c 65 74 65  |OGRAM=./oraclete|
000000d0  73 74 29 28 48 4f 53 54  3d 6b 73 6c 69 67 64 63  |st)(HOST=XXXXXXX|
000000e0  65 6f 64 73 72 76 30 32  29 28 55 53 45 52 3d 61  |XXXXXXXX)(USER=X|
000000f0  70 70 61 64 6d 69 6e 29  29 29 29                 |XXXXX))))|
sijms commented 9 months ago
func connect(host string, username string, password string, port int) (*sql.DB, error) {

    serviceName := "ORACLE"

    urlOptions := map[string]string{
        "TRACE FILE": "Trace.log",
                "SSL" : "TRUE",
                "SSL VERIFY": "FALSE",
                "WALLET": "path to wallet directory",
    }

    connStr := go_ora.BuildUrl(host, port, serviceName, username, password, urlOptions)
    fmt.Printf("Opening connection to db using go-ora: %v", connStr)

    // Connect to the database
    Connection, err := sql.Open("oracle", connStr)
    if err != nil {
        fmt.Println("Unable to open connection : " + err.Error())
        return nil, err
    }

    // Test the connection
    err = Connection.Ping()
    if err != nil {
        fmt.Println("Ping Failed : " + err.Error())
        Connection.Close()
        return nil, err
    }

}
mfichman commented 8 months ago

Also having this issue with a password containing !

sijms commented 8 months ago

use go_ora.BuildUrl for safe conversion of special character in username and password also see log file to catch the point where error occur