2

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
}
1
  • 2
    I this you have to call dB.QueryContext not dB.ExecContext Commented Nov 27, 2021 at 8:37

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.