Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article is a consolidation of useful tips while setting up your own Azure SQL Database and covers covers single-instance Azure SQL DBs (Elastic pools require separate design considerations beyond the scope of this article).
Spinning a new SQL DB is essentially a 4 step process and can be done via Azure portal, PowerShell and Visual Studio (C#), step by step description available on Azure documentation (SQL DB get started, see all 3 modes at the top).
Tip: Read Design Considerations section below before you procure your database and prevent that infinite loop of troubles.
Azure documentation (Connect to Sql database) covers how to connect through SSMS, C# and Excel. Will recommend a quick read on best practices related to connection pooling, timeouts, retry logic et al. Download the required connectivity libraries and get started with programming language of your choice, browse connections samples for .NET, Java, Node.js and many more here.
Most common error (once the firewall policy is added to allow access): A rule is added at the DB level to allow access for a given IP and you do not have access to server. This occurs when you have not specified the actual DB in the connection string so it defaults to master database that you do not have access. Changing your connection properties to include DB name with resolve this error.
Tip: If policy is added to database level, you will only see databases that you have access to (other DBs will be hidden from you)
By default, (when you create a new DB), Azure blocks ALL traffic to your database. The foundation is similar to Windows firewall and hence you must allow access through a “specific” port (Azure SQL Db always listens on port 1433). There are several ways to configure the firewall (Portal, TSQL, PowerShell, REST API) setup process described here. Access can be granted both at the server-level or at the db-level and it follows the hierarchy server ->database hence if you need to add a common range of IPs that can access all DBs you need to add at server level. Both the levels can be managed through Portal, TSQL, PowerShell and Rest API. For ports beyond 1433 , ADO.NET 4.5 or later (TDS 7.4) SQL database V11 always connect using proxy route (ADO .NET -> Middleware -> SQL) however with V12 there is now clear separation between Outside and Inside of Azure boundary (Azure doc). For outside, port 1433 is the only port that must be open at the application end. For all inside calls, Azure uses direct route (ADO.NET -> SQL) using the port ranges 11000-11999 and 14000-14999 so please ensure these are left available.
Tip: Block TCP Port 1433 for inbound only since Azure uses TCP port 1433 for outbound connections (for the TDS protocol) hence need to be opened however, make sure it is blocked for inbound connections and used only for outbound.
Access within Azure: This can be toggled by “Allow access to Azure services” Yes/No button on the portal (Firewall settings page). Please note, enabling this feature would allow any traffic from resources/services hosted in Azure (not just your Azure subscription) to access the database.
Access at the Server-level (On-Premise or anywhere outside Azure) : On the Azure portal -> Server -> Firewall settings page, add a policy (give a name) and list the starting and ending range for the IP address (will not suggest using single IP address as these change often and you may need to repair often). All these rules are “server-level” rules and can also be easily created through TSQL by using sp_set_firewall_rule (use sys.firewall_rules to find what rules exist your DB server and sp_set_database_firewall_rule to create policy at database level). You will see a specific entry for “Access within Azure” if turned ON.
Tip: These firewall settings are only to open ports, there is no setting to deny an IP address.
All connections to Azure SQL Database use SSL/TLS to protect your data while its “in transit”. Azure SQL Database can help protect your data by encrypting your data when "at rest," or stored in database files and backups, using Transparent Data Encryption. Additionally, you may consider using Cell-level encryption (specific columns or even specific cells of data).
Authentication refers to how you prove your identity when connecting to the database and ensures you must have a valid login to SQL Server. Azure SQL Database supports two types of authentication (more details here..)
· SQL Authentication, which uses a username and password
· Azure Active Directory Authentication, which uses identities managed by AAD (Azure documentation on set-up)
Authorization ensures you have permissions to access DB objects and is similar to the on premise SQL Server. Authorization/manage database access and login policies – excellent Azure documentation comparing differences between on-premise and Azure SQL DB access management (more details here..).
Local firewalls typically restrict port 1433/1434 outbound and could be an uphill task in organizations to get changed (these are restricted due to SQL slammer and Snake viruses) however, SQL Azure uses port 1433 for communication. If the port is blocked, the connection attempt times out hence there could be a few solutions possible:
SQLi is arguably one of the top threats to a database and basic firewall protection cannot always prevent such attacks (given the nature that the attack comes from compromised yet legitimate IP addresses). While implementing best coding practices goes a long way, I would recommend using Hexatier (formerly GreenSQL) like apps that ensures great degree of firewall protection (includes automated SQLi injection detection). Hexatier also provides advanced firewall definitions to assign granular-level definitions specifically to the individual (DBAs, Testers, Developers), IP addresses and Apps that can access specific areas of the database. ((https://www.hexatier.com/hexatier-for-sql-azure/)
All said above, there is great documentation available on Azure documentation website and it continues to be upgraded as newer features are rolled out so please use that judiciously over all other sources https://azure.microsoft.com/en-us/documentation/articles/sql-database-get-started/
Please sign in to use this experience.
Sign in