-
Notifications
You must be signed in to change notification settings - Fork 537
Support Azure Account Key parameter in connection strings #378
Description
Repro Steps
- From Azure portal, copy the connection string for an Azure SQL database (used below).
- Create a new .NET Framework 4.6.1 console app, with the following entry point:
using DbUp;
using DbUp.SqlServer;
namespace MadeForReleasio.SqlFramework
{
internal static class Program
{
private static void Main()
{
var connectionString = "DefaultEndpointsProtocol=https;AccountName=madeforreleasiostorage;AccountKey=(*redacted*);EndpointSuffix=core.windows.net";
EnsureDatabase
.For
.SqlDatabase(connectionString, AzureDatabaseEdition.Basic);
}
}
}
- Install NuGet package
dbup-sqlserverversion 4.1.0, so that the above compiles. - Run.
This exception is thrown:
System.ArgumentException
HResult=0x80070057
Message=Keyword not supported: 'defaultendpointsprotocol'.
Source=System.Data
StackTrace:
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)
at SqlServerExtensions.SqlDatabase(SupportedDatabasesForEnsureDatabase supported, String connectionString, AzureDatabaseEdition azureDatabaseEdition)
at MadeForReleasio.SqlFramework.Program.Main() in D:\Software\My Software\MadeForReleasio\MadeForReleasio.SqlFramework\Program.cs:line 11
Other info
I also get this error for other operations, like UpgradeEngine.IsUpgradeRequired(), or UpgradeEngine.PerformUpgrade().
I tried removing DefaultEndpointsProtocol=https; and tried again, but it then errors with Keyword not supported: 'accountname'.
Do I have to do something special to connect to an Azure database? There doesn't appear to be any documentation on working with Azure SQL databases, besides the Supported Databases doc page, which simply says "Sql Azure >= .NET 3.5". While the Repro Steps use .NET Framework 4.6.1, the same results occur on .NET Core 2.1, so I suspect it's framework-independent.
Workaround
I was able to successfully connect by hand-writing a normal SQL Authentication-formatted connection string, instead of a cloud-provider formatted connection string:
Data Source=madeforreleasio.database.windows.net;Initial Catalog=MadeForReleasio-Sql;User Id=(*redacted*);Password=(*redacted*)