You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot read database label from the connection string (driver=sqlserver) #162
When I check the metrics (http://localhost:9237/metrics) I can see the correct metric I configured and the correct labels coming from the exporter itself except database label.
See below: I did not set driver, host, user labels, it reads from the connection string but database
Hey @sadedil, are you sure the current way we support doesn't work? I'm seeing a similar url being used in this project and I would've also expected there to be previous cases being flagged as something basic as the dbname parameter wouldn't work.
Actually, it felt a bit strange to me at first, but when I looked into the sql_exporter code, I saw that it expects the connection string for all databases in URL format (I’m more of a .NET person, so it wasn’t something I was very used to, but I got it).
Since a URL has its own specification, it’s naturally made up of certain parts.
URL1 (standard web url): https://example.com:8080/products/electronics?category=phones&sort=price#reviews
for Microsoft SQL Server, /dbname can be /instance/dbname, where /instance is optional. For Oracle Database, /dbname is of the form /service/dbname where /service is the service name or SID, and /dbname is optional. Please see below for examples.
When I prepared the connection string like this, my problem was solved.
Sorry for spamming, but now I tried this on our project and this url query style @host1.database.windows.net:1433/db1?... has limited support for Azure SQL and Azure Managed Instance databases
I've started to get these errors
mssql: login error: Database 'master' on server '' is not currently available. Please retry the connection later.
database must be specified when ApplicationIntent is ReadOnly
Activity
dewey commentedon Sep 10, 2025
Happy to review a PR if you want to give it a try :)
sadedil commentedon Sep 10, 2025
I've tried, please check the merge request.
sadedil commentedon Sep 17, 2025
Hello @dewey, any plans to review/merge?
Thank you
dewey commentedon Sep 17, 2025
Thanks for the reminder, will check tomorrow.
dewey commentedon Sep 22, 2025
Hey @sadedil, are you sure the current way we support doesn't work? I'm seeing a similar url being used in this project and I would've also expected there to be previous cases being flagged as something basic as the dbname parameter wouldn't work.
sadedil commentedon Sep 22, 2025
Hi @dewey,
Actually, it felt a bit strange to me at first, but when I looked into the
sql_exportercode, I saw that it expects the connection string for all databases in URL format (I’m more of a .NET person, so it wasn’t something I was very used to, but I got it).Since a URL has its own specification, it’s naturally made up of certain parts.
https://example.com:8080/products/electronics?category=phones&sort=price#reviewssqlserver://user1:[email protected]:1433?database=db1&encrypt=true&TrustServerCertificate=true&connection+timeout=15&app name=sql_exporter_localLet's analyze the parts:
<-- the problemStrangely enough, the
dburllibrary you pointed out gives an example like this:sqlserver://user:[email protected]/dbnameHowever, in the
microsoft/go-mssqldblibrary there’s no usage like/dbname; instead, it only supports something like/instance?database=dbname.Here’s an example taken directly from there:
sqlserver://sa@localhost/SQLExpress?database=master&connection+timeout=30 // SQLExpress instance.Another point is that I also have a working example related to this.
sadedil commentedon Sep 22, 2025
I just checked again,
I saw this note in the dburl:
When I prepared the connection string like this, my problem was solved.
Sorry for the trouble.
sqlserver://user1:[email protected]:1433/db1?encrypt=true&TrustServerCertificate=true&connection+timeout=15&app name=sql_exporter_localsadedil commentedon Sep 22, 2025
Sorry for spamming, but now I tried this on our project and this url query style
@host1.database.windows.net:1433/db1?...has limited support for Azure SQL and Azure Managed Instance databasesI've started to get these errors
mssql: login error: Database 'master' on server '' is not currently available. Please retry the connection later.database must be specified when ApplicationIntent is ReadOnlyThe decision is yours.
dewey commentedon Sep 22, 2025
Hey @sadedil, I've merged the changes. I don't have a msql server myself to test but as you verified that's working for you let's get it in.
Thanks for the contribution!
sadedil commentedon Sep 22, 2025
Thank you, @dewey, for open-sourcing this project.
When are you planning to release the new Docker image?
dewey commentedon Sep 22, 2025
The job is running, should be pushed any moment: https://github.com/justwatchcom/sql_exporter/actions