Home > Enterprise >  Golang SQL error expected 0 arguments got 3
Golang SQL error expected 0 arguments got 3

Time:11-27

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
}

CodePudding user response:

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.

  • Related