Как упоминал Джои Кай, вы можете создать правило брандмауэра, чтобы принимать доступ со всех IP-адресов. Однако мы решили эту проблему, создав приложение, которое наши пользователи в дороге запускают, чтобы обновить для них правила брандмауэра и получить доступ к базе данных SQL Azure.
Из C # вы можете получить доступ ко всем ресурсам Azure через Microsoft.Azure. Management.Fluent, как это
// 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 откроет окно входа в систему и, следовательно, не может использоваться в автоматическом режиме. Вы можете предоставить токен-кеш с уже сохраненным токеном, если хотите войти в систему только один раз.