[Windows Azure] Development Considerations in Windows Azure SQL Database
Development Considerations in Windows Azure SQL Database
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:
- By using the Management Portal.
- By using the CREATE DATABASE statement.
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:
- Host your application code on-premises at your own corporate data center, but host your database in SQL Database. Your application code uses client libraries to access the database(s) in SQL Database. For more information about the client libraries that are available, see Guidelines and Limitations (Windows Azure SQL Database). For example code, see How to: Connect to Windows Azure SQL Database Using ADO.NET topic.
- Host your application code in Windows Azure and your database in SQL Database. Your application can use the same client libraries to access the database(s) in SQL Database. In this case, your client application may be a desktop or Silverlight application that uses the benefits of the Entity Data Model and the WCF Data Services client to access data that is hosted in SQL Database. For example code, see How to: Connect to Windows Azure SQL Database Through WCF Data Services.
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的更多相关文章
- [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 ...
- [Windows Azure] Windows Azure SQL Database library
Microsoft Windows Azure SQL Database extends SQL Server capabilities to the cloud. SQL Database offe ...
- [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 ...
- [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 ...
- [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 ...
- 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 ...
- 使用SQL Database Migration Wizard把SQL Server 2008迁移到Windows Azure SQL Database
本篇体验使用SQL Database Migration Wizard(SQLAzureMW)将SQL Server 2008数据库迁移到 Azure SQL Database.当然,SQLAzure ...
- [Windows Azure] Windows Azure Storage & SQL Database
http://channel9.msdn.com/Series/Windows-Azure-Storage-SQL-Database-Tutorials Windows Azure offers mu ...
- [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 - ...
随机推荐
- 创业成本?亲身经历告诉你做一个app要多少钱
导语:作为一名苦逼的移动互联网创业者,被外行的朋友们问及最多的问题是“做一个网站需要多少钱?”或者“做一个APP需要多少钱?” 作为一名苦逼的移动互联网创业者,被外行的朋友们问及最多的问题是“做一个网 ...
- js中setTimeout、setInterval、 clearInterval方法简介
setTimeout setTimeout(code, millisec) 用于在指定的毫秒数后调用函数或计算表达式. 说明: setTimeout()只执行一次code.如果要多次调用,要使用set ...
- [转]nonlocal和global
在Python中,当引用一个变量的时候,对这个变量的搜索是按找本地作用域(Local).嵌套作用域(Enclosing function locals).全局作用域(Global).内置作用域(bui ...
- ubuntu 连接windows远程桌面 &&rdesktop 退出全屏模式
参考:http://www.asgone.net/ubuntu-connect-windows-remote-desktop/ 呵呵,使用上了ubuntu,怎么接连上我的服务器的远程桌面呢,找了找帮助 ...
- iOS开发调试Reveal使用
推荐通过Xcode中加断点的方式集成Reveal(小缺陷,当你禁用断点时或者不用Xcode而用Appcode开发时,这个方式是不管用). 打开您的iOS工程,选择 View → Navigators ...
- 【DeepLearning】UFLDL tutorial错误记录
(一)Autoencoders and Sparsity章节公式错误: s2 应为 s3. 意为从第2层(隐藏层)i节点到输出层j节点的误差加权和. (二)Support functions for ...
- NBUT [1475] Bachelor
[1475] Bachelor http://acm.nbut.cn:8081/Problem/view.xhtml?id=1475 时间限制: 1000 ms 内存限制: 65535 K 问题描述 ...
- 微信多客服插件获取openid
<!doctype html> <html> <head> <meta http-equiv="Content-Type" content ...
- Linux MySQL 4G内存my.cnf配置表(转)
# The following options will be passed to all MySQL clients[client]character-set-server = utf8 #### ...
- solr开发从查询结果集中获取对象数据
solrJ从查询结果集中获取对象数据. 方案一:自定义转换方式 /** * * SolrDocument与实体类转换 [测试通过] * * @author pudongping * * @param ...
Note