Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empties queries with microsoft/mssqldb package #1594

Closed
dmathieu opened this issue Mar 18, 2024 · 2 comments
Closed

Empties queries with microsoft/mssqldb package #1594

dmathieu opened this issue Mar 18, 2024 · 2 comments
Labels

Comments

@dmathieu
Copy link
Member

          Hello guys, thank you for the switch to microsoft package!

There might be an issue btw, I am not able to perform a SELECT Id FROM Table WHERE Id = $1 ; I get a no rows returned from row.Scan.
Actually I am able to retrieve rows using the formatted query:

// NOK
	query := "SELECT Id FROM Customer WHERE Id = $1"
	var customer Customer
	row := db.QueryRowContext(apm.ContextWithTransaction(context.Background(), tx), query, 2)
// OK
	query := fmt.Sprintf("SELECT Id FROM Customer WHERE Id = %d", 2)
	var customer Customer
	row := db.QueryRowContext(apm.ContextWithTransaction(context.Background(), tx), query)

Here is how I init my db instance:

package main

import (
	"context"
	"database/sql"
	"encoding/json"
	"fmt"
	"os"

	"github.com/sirupsen/logrus"
	"go.elastic.co/apm/module/apmsql/v2"
	_ "go.elastic.co/apm/module/apmsql/v2/sqlserver"
	"go.elastic.co/apm/v2"
)

func main() {
	settings, err := LoadSettings("server.conf.json")
	dsn := settings.Database.String("go-test")
	db, err := apmsql.Open("sqlserver", dsn)
	if err != nil {
		logrus.StandardLogger().Fatal(err)
	}
	defer db.Close()

Originally posted by @thibleroy in #1569 (comment)

@dmathieu
Copy link
Member Author

Thank you for reporting this @thibleroy. Your code sample is a bit too short to be something reproducible.
Would you be able to setup a short working example?

Does it work without the apmsql package?

@thibleroy
Copy link

I can explain the issue we faced now. We were connecting using the mssql:// prefix in the DSN. However, to use the apmsql package, we must use the sqlserver:// prefix, right? Here is the explanation: Microsoft go-mssqldb README. Therefore, I believe we should close this issue, as it pertains to the MSSQL driver and its usage.

@dmathieu dmathieu closed this as not planned Won't fix, can't repro, duplicate, stale Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants