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

can use USE switch db #36

Closed
labulakalia opened this issue Jul 11, 2022 · 2 comments
Closed

can use USE switch db #36

labulakalia opened this issue Jul 11, 2022 · 2 comments

Comments

@labulakalia
Copy link

Describe the bug
use USE mydb can not switch mydb,
but use sqlcmd can switch

To Reproduce
Include a complete code listing that we can run to reproduce the issue.

db.ExecContext(context.Background(), "USE mydb")
db.ExecContext(context.Background(), "SELECT db_name()")

but get dbname not is mydb,
i set

sqlDb.SetMaxOpenConns(1)
sqlDb.SetMaxIdleConns(1)

Expected behavior
A clear and concise description of what you expected to happen.

Further technical details

SQL Server version: SQL Server 2019
Operating system: Docker container
Table schema

Additional context
Add any other context about the problem here.

@shueybubbles
Copy link
Collaborator

I don't think the database/sql model has any guarantee that subsequent calls to ExecContext or similar methods would reuse the same physical connection.

I think you need to use db.Conn(context.Background()) to get a reusable physical connection.

@labulakalia
Copy link
Author

Thank you,I use Conn solve my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants