Azure sql database 如何配置数据库,以便从任何计算机进行连接?

Azure sql database 如何配置数据库,以便从任何计算机进行连接?,azure-sql-database,Azure Sql Database,我是Azure的新成员,可以使用您的服务器创建一个数据库,作为一个团队工作。但我必须将IP添加到每个防火墙中。问题是IP发生了变化,必须更新IP。我需要知道是否有其他形式的配置可以从任何IP访问吗?建议使用某种中间件访问数据库,而不是直接访问您的客户端 但是,如果您希望任何IP能够连接到db,只需将此条目添加到防火墙列表: Azure门户->Azure Sql Server->数据库->设置服务器防火墙并添加以下规则: 正如Joey Cai提到的,您可以创建一个防火墙规则来接受来自所有IP地址的

我是Azure的新成员,可以使用您的服务器创建一个数据库,作为一个团队工作。但我必须将IP添加到每个防火墙中。问题是IP发生了变化,必须更新IP。我需要知道是否有其他形式的配置可以从任何IP访问吗?

建议使用某种中间件访问数据库,而不是直接访问您的客户端

但是,如果您希望任何IP能够连接到db,只需将此条目添加到防火墙列表:

Azure门户->Azure Sql Server->数据库->设置服务器防火墙并添加以下规则:


正如Joey Cai提到的,您可以创建一个防火墙规则来接受来自所有IP地址的访问。然而,我们通过构建一个应用程序解决了这个问题,我们的用户可以在路上运行该应用程序来更新防火墙规则,并获得对Azure SQL数据库的访问权

从C#可以通过Microsoft.Azure.Management.Fluent访问所有Azure资源,如下所示

// Create an authentication context to Azure and acquire a login token
var context = new AuthenticationContext("https://login.microsoftonline.com/tenantId");
var auth = await context.AcquireTokenAsync("https://management.core.windows.net/",
                    "yourClientId", new Uri("urn:ietf:wg:oauth:2.0:oob"),
                    new PlatformParameters(PromptBehavior.Always));
var tokenCredentials = new TokenCredentials(token);
var azureCredentials = new AzureCredentials(tokenCredentials, tokenCredentials, 
                           AzureParts.Tenant, AzureEnvironment.AzureGlobalCloud);

// Build the client with the acquired token as a credential.
RestClient client = RestClient.Configure()
                .WithEnvironment(AzureEnvironment.AzureGlobalCloud)
                .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                .WithCredentials(azureCredentials)
                .Build();

// Authenticate against azure with the correct subscription to access.
var azure = Azure.Authenticate(client, AzureParts.Tenant)
                .WithSubscription("subscriptionId");

// Search for the sql server and add a firewall rule.
var sqlServer = azure.SqlServers.GetByResourceGroup("ResourceGroup", "servername");
sqlServer.FirewallRules.Define("LetMeIn").WithIPAddress("yourIp").Create();

请注意,通过AcquireTokenAsync获取登录令牌将打开登录窗口,因此不能以自动方式使用。如果您只想登录一次,可以使用已存储的令牌提供令牌缓存。

非常感谢,这非常有用。中间件对于提高安全性也很有用