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

Use Microsoft.Data.SqlClient to allow Azure Active Directory connections #15

Open
chriswill opened this issue Apr 6, 2021 · 12 comments · May be fixed by #17
Open

Use Microsoft.Data.SqlClient to allow Azure Active Directory connections #15

chriswill opened this issue Apr 6, 2021 · 12 comments · May be fixed by #17
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@chriswill
Copy link

chriswill commented Apr 6, 2021

Referencing this post.

I want to use a SQL connection string like
Server=myserver.database.windows.net,1433;Database=mydatabase;UID=a;Authentication=Active Directory Interactive

but the app fails with a Keyword not supported: 'authentication' exception. This is because System.Data.SqlClient doesn't understand the new authentication schemes supported in Microsoft.Data.SqlClient that support Sql Azure.

Upgrading to Microsoft.Data.SqlClient is a relatively painless process and would resolve this issue. Would you accept a PR for this?

Note: I applied the overloads to .SqlDatabase suggested in #7 but this did not help.

@chriswill chriswill added the enhancement New feature or request label Apr 6, 2021
@chriswill chriswill changed the title Use Microsoft.Data.SqlClient Use Microsoft.Data.SqlClient to allow Azure Active Directory connections Apr 6, 2021
@chriswill
Copy link
Author

I forked the repo and updated the dbup-sqlserver project to use Microsoft.Data.SqlClient and this resolved the issue.

@Hooch180
Copy link

When will the support for Microsoft.Data.SqlClient be added?

@chriswill
Copy link
Author

@Hooch180 For one reason or another it seems like PRs are not being accepted here in a timely fashion. You're welcome to use my fork https://github.com/chriswill/DbUpReboot if you need Microsoft.Data.SqlClient support.

@JCarnall
Copy link

JCarnall commented May 5, 2021

@chriswill, many thanks, just grabbed your 'DbUp.Reboot' package and it works a charm using the newer connection string format for Azure Sql

@TroyWitthoeft
Copy link

@chriswill - Good to see someone out there picking up a reboot for DbUp! Thank you. Let me know if I can help. Thanks for pointing out the new connection string authentication keywords in Microsoft.Data.SqlClient. FWIW, the overload in #7 is working for me? I've also got an example of how to manually do something like Active Directory Default does in the TestConnect() method of AzureDbUp, here.

@chriswill
Copy link
Author

@TroyWitthoeft good luck with your project!

@LordBenjamin
Copy link

+1 for this request - I'm getting an error after upgrading to .NET 6.0 (which has resulted in having to add TrustServerCertificate=True for local dev).

Any update from the maintainers would be appreciated. Happy to contribute if there is anything I can do to help?

Keyword not supported: 'trust server certificate'
at System.Data.SqlClient.SqlConnectionStringBuilder.GetIndex(String keyword)
at System.Data.SqlClient.SqlConnectionStringBuilder.set_Item(String keyword, Object value)
at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
at System.Data.SqlClient.SqlConnectionStringBuilder..ctor(String connectionString)
at SqlServerExtensions.GetMasterConnectionStringBuilder(String connectionString, IUpgradeLog logger, String& masterConnectionString, String& databaseName)
at SqlServerExtensions.SqlDatabase(SupportedDatabasesForEnsureDatabase supported, String connectionString, IUpgradeLog logger, Int32 timeout, AzureDatabaseEdition azureDatabaseEdition, String collation)

@osexpert
Copy link

I wonder why this is still open? It seems to work fine now (tested net60 + dbup-sqlserver 5.0.8)

@mjauernig
Copy link
Member

@osexpert Thank you for the feedback. I will test it in the next days and then close the issue.

@JumpingJezza
Copy link

The latest version still does not work for passwordless Managed Identities.
Testing with a .Net Framework 4.8 project and using a connection string like this:
"data source=<resource>.database.windows.net;initial catalog=<database name>;Authentication=Active Directory Managed Identity;...other properties"

Code:

var upgrader = DeployChanges.To.SqlDatabase(_connectionString)
   .WithScriptsEmbeddedInAssembly(typeof(DbScriptAutomation).Assembly)
   .LogToConsole()
   .WithExecutionTimeout(TimeSpan.FromSeconds(timeout))
   .Build();

throws an error:
System.ArgumentException: Invalid value for key 'authentication'

The same connection string can be used to connect successfully using the Microsoft.Data.SqlClient.
The old System.Data.SqlClient however throws the same Invalid value for key 'authentication' error.

@kAleksei
Copy link

Hi everyone. Do you have any updates on it? The package System.Data.SqlClient is considered highly vulnerable: https://avd.aquasec.com/nvd/2024/cve-2024-0056. It would be great if it could be prioritized!

@droyad
Copy link
Member

droyad commented Feb 23, 2024

@kAleksei The SqlServer provider already uses version 4.8.6 which is listed as fixed in that CVE

@droyad droyad transferred this issue from DbUp/DbUp Feb 23, 2024
@droyad droyad added this to the 6.0.0 milestone Feb 23, 2024
@droyad droyad linked a pull request Mar 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: v6
Development

Successfully merging a pull request may close this issue.

10 participants