由于安全原因,SQL身份验证被禁用,我只能通过Azure SPN登录。通过下面的链接,我们可以在C#中连接:
如何在下面的DbUp program.cs中传递上述成功的访问令牌认证连接?
var upgrader = DeployChanges.To.AzureSqlDataWarehouse(connectionString)
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
.LogToConsole()
.LogScriptOutput().WithExecutionTimeout(TimeSpan.FromSeconds(60))
.Build();
var result = upgrader.PerformUpgrade();发布于 2020-07-28 12:20:40
不确定您是否已解决此问题,但希望提供合适的答案,因为它可能会帮助其他人寻找相同或类似的解决方案。首先,在查看DbUp时,我没有看到任何对Azure AD身份验证的本地支持,但我认为以下是您正在寻找的。
Token-based authentication support for Azure SQL DB using Azure AD auth
链接的技术社区博客讨论了您可以用Azure SQL进行身份验证的所有Azure AD方法。它包含一个演示基于令牌的身份验证的示例应用程序(TokenReadme.Zip),其中TokenReadme.docx中包含的program.cs示例如下:
using System;
using System.Data;
using System.Data.SqlClient;
namespace ClinicService
{
class Program
{
static void Main()
{
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
builder["Data Source"] = "aad-managed-demo.database.windows.net"; // replace with your server name
builder["Initial Catalog"] = "demo"; // replace with your database name
builder["Connect Timeout"] = 30;
string accessToken = TokenFactory.GetAccessToken();
if (accessToken == null)
{
Console.WriteLine("Fail to acuire the token to the database.");
}
using (SqlConnection connection = new SqlConnection(builder.ConnectionString))
{
try
{
connection.AccessToken = accessToken;
connection.Open();
Console.WriteLine("Connected to the database");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
Console.WriteLine("Please press any key to stop");
Console.ReadKey();
}
}
}您应该能够利用TokenReadme示例修改您的DbUp .NET库解决方案,以利用基于令牌的身份验证。问候你,迈克
发布于 2022-01-11 14:26:04
DbUp应该在DeployChanges.To.AzureSqlDataWarehouse调用中公开一个布尔值,以便在内部使用令牌身份验证。不幸的是,您不能传递已有的令牌。
DeployChanges.To.AzureSqlDataWarehouse(connectionString,true)https://stackoverflow.com/questions/62733591
复制相似问题