Development Considerations in Windows Azure SQL Database

3 out of 5 rated this helpful - Rate this topic

Developing applications for Microsoft Windows Azure SQL Database is very similar to developing applications for SQL Server. This topic describes a few differences and some considerations when developing Windows Azure SQL Database applications. In addition, the topic provides the basic steps that you need to take as a developer and lists the recommended coding practices.

Creating SQL Database Servers

To use Windows Azure SQL Database, you must first create a Windows Azure platform account. The Windows Azure account is used to set up and manage your subscriptions and to bill for consumption of Windows Azure, Windows Azure AppFabric, and Windows Azure SQL Database. Once the Windows Azure account is created, you can use the Windows Azure Platform Management Portal to add or drop a SQL Database server and a database. You can also use the Windows Azure SQL Database Management API to programmatically add or drop SQL Database servers and manage firewall rules associated to a server.

A SQL Database server is a logical group of databases and acts as a central administrative point for multiple databases. When you create a SQL Database server, a read-only master database is created automatically. The master database keeps track of which logins have permission to create databases or other logins. You must be connected to the master database whenever you CREATE, ALTER, or DROP logins or databases. For more information on security administration in Windows Azure SQL Database, see Managing Databases and Logins in Windows Azure SQL Database.

By default, all access to your SQL Database server is blocked by the SQL Database firewall. To begin using your SQL Database server, you must specify one or more server-level firewall rules that enable access to your SQL Database server. The server-level firewall rules can be managed using the Management Portal user interface, or programmatically using the Database Management API. Before you can use the Database Management API, you must add a certificate for authentication as described in Authenticating Windows Azure SQL Database Management API Requests.

After you have created a server-level firewall setting, you can use the server-level principal login and the master database to view and edit your firewall settings. In the master database, the firewall settings are referred to as rules. The sys.firewall_rules view displays the current server-level firewall settings, and the sp_set_firewall_rule and sp_delete_firewall_rule stored procedures allow you to change the server-level firewall rules.

Further, if you want to control access to certain databases in your SQL Database server, you can create database-level firewall rules for those databases. You can create database-level firewall rules for the master and user databases. You can connect to a database and view the database-level firewall rules in the sys.database_firewall_rules view. The sp_set_database_firewall_rule and sp_delete_database_firewall_rule stored procedures in the master and user databases allow you to change the database-level firewall rules for the respective database. For more information about the server-level and database-level firewall rules, see Windows Azure SQL Database Firewall.

You can access the billing details of your SQL Database accounts on the SQL Database server by using sys.database_usage and sys.bandwidth_usage system views. For more information, see Accounts and Billing in Windows Azure SQL Database.

Creating SQL Databases

There are two ways to create SQL Databases:

For information about how to migrate a database from an on-premise instance of SQL Server to SQL Database, see Migrating Databases to Windows Azure SQL Database (formerly SQL Azure).

In addition, a code example provided in How to: Connect to Windows Azure SQL Database Using ADO.NET demonstrates how to use the CREATE DATABASE statement in client application code.

Note
To change the edition and name of your database after creation, you can use the ALTER DATABASE statement.

Building and Hosting SQL Database Applications

There are two ways to build and host Windows Azure SQL Database applications:

You can minimize the network latency of requests to the SQL Database by hosting your application in the Windows Azure platform. Deploying your application to Windows Azure provides more efficient transactions between your application and SQL Database compared to an application hosted outside Windows Azure. For more information about hosting your application and data in the cloud, see Windows Azure SQL Database Data Access.

Bandwidth used between SQL Database and Windows Azure or Windows Azure AppFabric is free within the same sub-region or data center. When deploying a Windows Azure application, locate the application and the SQL Database in the same sub-region to avoid bandwidth costs. For more information, see Accounts and Billing in Windows Azure SQL Database.

Developing SQL Database Applications

Developing applications for Windows Azure SQL Database is very similar to developing applications for SQL Server. You can choose from many application types and technologies when you develop an application that accesses Windows Azure SQL Database. Windows Azure SQL Database works with third-party applications, PHP, and many Microsoft applications, such as ADO.NET, the Entity Framework, WCF Data Services, and ODBC.

Windows Azure SQL Database provides a large-scale multi-tenant database service on shared resources. In order to provide a good experience to all Windows Azure SQL Database customers, your connection to the service may be closed due to the following conditions:

  • Excessive resource usage
  • Long-running queries
  • Long-running single transactions, between the BEGIN TRAN and END TRAN statements
  • Idle connections

This is different from how an on-premise instance of SQL Server works.

To provide a seamless user experience when a connection is closed, incorporate retry logic in your application to detect a closed connection and then attempt to complete the interrupted action. For more information on connection limitations in Windows Azure SQL Database, see General Guidelines and Limitations (Windows Azure SQL Database).

When the client application connects to Windows Azure SQL Database, CONTEXT_INFO (Transact-SQL) is set with a unique session specific GUID value automatically. Retrieve this GUID value and use it in your application to trace the connectivity problems.

The following C# code statements demonstrate how to modify your application to trace the connectivity.

// Define global variables.
private static Dictionary<SqlConnection, Guid> _cache = new Dictionary<SqlConnection, Guid>();
public static SqlConnection conn; // Connect to the sample database.
using (conn = new SqlConnection(connStringBuilder.ToString()))
{
// Define the event handler.
conn.StateChange += new StateChangeEventHandler(OnConnectionStateChange);
conn.Open();
using (SqlCommand command = conn.CreateCommand())
{
// Perform a query or an update.
// Retrieve the session ID.
Guid id = SessionId(conn);
conn.Close();
}
} // Retrieve the session ID to track the connectivity.
public static Guid SessionId(this SqlConnection conn)
{
return _cache[conn];
} // Implement your event handler.
public static void OnConnectionStateChange(object sender, StateChangeEventArgs e)
{
SqlConnection conn = (SqlConnection)sender;
switch (e.CurrentState)
{
case ConnectionState.Broken:
Console.WriteLine("Connection is broken...");
_cache.Remove(conn);
break;
case ConnectionState.Closed:
Console.WriteLine("Connection is closed...");
_cache.Remove(conn);
break;
case ConnectionState.Open:
Console.WriteLine("Connection is open...");
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "SELECT CONVERT(NVARCHAR(36), CONTEXT_INFO())";
_cache[conn] = new Guid(cmd.ExecuteScalar().ToString());
}
break;
}
}

See Also

[Windows Azure] Development Considerations in Windows Azure SQL Database的更多相关文章

  1. [Windows Azure] How to Create and Configure SQL Database

    How to Create and Configure SQL Database In this topic, you'll step through logical server creation ...

  2. [Windows Azure] Windows Azure SQL Database library

    Microsoft Windows Azure SQL Database extends SQL Server capabilities to the cloud. SQL Database offe ...

  3. [Windows Azure] How to Scale a SQL Database Solution

    How to Scale a SQL Database Solution On Windows Azure, database scalability is synonymous with scale ...

  4. [Windows Azure] Guidelines for Connecting to Windows Azure SQL Database

    Guidelines for Connecting to Windows Azure SQL Database 6 out of 12 rated this helpful - Rate this t ...

  5. [Windows Azure] Managing SQL Database using SQL Server Management Studio

    Managing Windows Azure SQL Database using SQL Server Management Studio You can use Windows Azure SQL ...

  6. How to Use Lucene.NET with Windows Azure SQL Database

    http://social.technet.microsoft.com/wiki/contents/articles/2367.how-to-use-lucene-net-with-windows-a ...

  7. 使用SQL Database Migration Wizard把SQL Server 2008迁移到Windows Azure SQL Database

    本篇体验使用SQL Database Migration Wizard(SQLAzureMW)将SQL Server 2008数据库迁移到 Azure SQL Database.当然,SQLAzure ...

  8. [Windows Azure] Windows Azure Storage & SQL Database

    http://channel9.msdn.com/Series/Windows-Azure-Storage-SQL-Database-Tutorials Windows Azure offers mu ...

  9. [Windows Azure] Monitoring SQL Database Using Dynamic Management Views

    Monitoring Windows Azure SQL Database Using Dynamic Management Views 5 out of 7 rated this helpful - ...

随机推荐

  1. ubuntu 16.04 LTS 修改 国内源(以中科大源为例)

    国内有很多ubuntu的源,包括:网易源(这个之前用过,速度很快的),阿里源,还有很多教育网的源,如:清华源,中科大源. 这里要下载的是中科大ubuntu16.04的源列表,可以在这里获得:https ...

  2. TxQueryRunner

    package cn.itcast.jdbc; import java.sql.Connection; import java.sql.SQLException; import org.apache. ...

  3. Git/Github的使用以及与Eclipse的整合

    Git简介       Git是一个免费的.分布式的版本控制工具,或是一个强调了速度快的源代码管理工具.每一个Git的工作目录都是一个完全独立的代码库,并拥有完整的历史记录和版本追踪能力,不依赖于网络 ...

  4. (转)IntelliJ IDEA java项目导入jar包,打jar包

    以下为转载原文:https://www.cnblogs.com/yulia/p/6824058.html 一.导入 1.java项目在没有导入该jar包之前,如图: 2.点击 File ->   ...

  5. Ubuntu下查看软件版本及安装位置【转】

    Ubuntu下查看软件版本及安装位置 查看软件版本:     aptitude show xxx 也可用apt-show-versions (要先安装sudo apt-get install apt- ...

  6. kafka负载均衡相关资料收集(三)

    apache kafka系列之Producer处理逻辑 下文是转载的,原文链接地址:点这儿 [转] Kafka ProducerKafka Producer处理逻辑kafka生产者处理逻辑apache ...

  7. Entity Framework 4.0 recipes 读书笔记2 ExecuteStoreQuery()

    写在之前:我想通过refector 反编译一下system.data.entity.dll(4.0 version),发现反编译出来的只有属性申明和方法声明,里面一句代码都没有,真是火大啊,试了几个. ...

  8. java 高性能读模式(译)

    原文地址:http://tutorials.jenkov.com/java-performance/read-patterns.html 好久没翻译了,逛知乎,无意间发现的一个链接,写的太好了,而且内 ...

  9. Mac添加快捷键开启应用程序(转)

    最近使用终端比较多点,打开终端的方法有几种:比较常用有把终端添加到Dock栏上,然后就是利用Spotlight搜索Terminal来打开.但是两种方式还是让我感觉不太满意. 当开启的程序比较多的时候, ...

  10. Intent----android中的伟大邮差

    在android中,intent就像是一个邮差,辛勤高效的在各个组件之间来回穿梭.我们可以通过它启动一个Activity或者Service,或者是发送给广播组件,又或者是与后台的Service进行通信 ...