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't connect to SQLServer when embedding username and password in connection string #3998

Open
1 of 2 tasks
mistermiracl opened this issue Mar 22, 2023 · 5 comments
Open
1 of 2 tasks

Comments

@mistermiracl
Copy link

mistermiracl commented Mar 22, 2023

Search first

  • I searched and no similar issues were found

Description

When running the command to run the migrations on an Azure SQL database
mvn liquibase:update

Having specified a properties file in the pom.xml with the database URL as follows:
url: jdbc:sqlserver://{url}:{port};database={database};username={username};password={password};encrypt=true;trustServerCertificate=false;hostNameInCertificate={hostname};loginTimeout=30;

Liquibase cannot establish a connection, and returns this message:
Login failed for user {username}

Interestingly enough, when booting the app using spring boot's command: mvn spring-boot:run, using the exact same connection string, the connection is established and the migrations are executed by liquibase successfully.

I should mention that if I specify both username and password properties in the liquibase.properties file the connection is established successfully, however I'm reusing this connection string other places and, unfortunately, I cannot access these other properties from outside.

Steps To Reproduce

execute the update goal in the liquibase maven plugin with a properties file with the username and password embeded in the url property

Expected/Desired Behavior

liquibase should be able to connect to the database using with the specified connection string

Liquibase Version

4.9.1

Database Vendor & Version

Azure SQL equivalent to SQLServer 2019

Liquibase Integration

maven

Liquibase Extensions

No response

OS and/or Infrastructure Type/Provider

Windows

Additional Context

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR (Thank you!)
@nvoxland
Copy link
Contributor

Liquibase doesn't currently support replacing properties in the URL, it only accepts it as a static value.

Are you able to remove the username/password from the url? Or is there a reason you need it them there?

@mistermiracl
Copy link
Author

@nvoxland Thing is, I'm using the same database url for my spring boot app's application.properties basically importing the liquibase.properties and referencing them using spring.config.import, I cannot reference the username property in there 'cause its also an environment variable. Also, Microsoft basically recommends using this standard of embedding the credentials in the connection string, so I was surprised Liquibase didn't support it, but spring boot does. Bottom line, I think repeating the same connection string in different places can be error prone, which is. unfortunately, what I've had to do in order to make it work.

@mistermiracl
Copy link
Author

@nvoxland also, I'm not attempting to replace the properties in the url, they're static, but even with that it doesn't work, I put the properties in curly braces as an example, didn't mean to cause confusion

@tati-qalified
Copy link
Contributor

Hello @mistermiracl, sorry for the late response. Would you be willing to submit a PR? Our team would provide you with guidance to help you out if needed.
Thank you
Tatiana

@TedKeenan
Copy link

Maybe a simple question but don't you need a ${} to get the values evaluated so
url: jdbc:sqlserver://${url}:${port};database=${database};username=${username};password=${password};encrypt=true;trustServerCertificate=false;hostNameInCertificate=${hostname};loginTimeout=30;

Or at least that works for me.

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

No branches or pull requests

6 participants