简体   繁体   中英

Golang SQL error expected 0 arguments got 3

I'm using github.com/denisenkom/go-mssqldb library and driver but getting an error sql: expected 0 arguments, got 3 exit status 1 when inserting new row.

tsql := "INSERT INTO Uploads (Fname, Fsize, Ftype) VALUES (@Fname, @Fsize, @Ftype );"
fmt.Printf("tsql = %s\n", tsql)

//Execute non-query with named parameters
res, err := db.ExecContext(
    ctx,
    tsql,
    sql.Named("Fname", fname),
    sql.Named("Fsize", fsize),
    sql.Named("Ftype", ftype))

if err != nil {
    log.Fatal(" AddRow_v1() -> Error creating new row: " + err.Error())
    return -1, err
}

This issue might be related to driver name used in the connection string. I've tried the same query with yours, the record is created without any errors.

I believe that you are currently using mssql in connection string; sql.Open("mssql", conn) (This issue has already been discussed in https://github.com/denisenkom/go-mssqldb/issues/594#issuecomment-809922317 )

If you try again by replacing "mssql" to "sqlserver", the problem should be solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM