Turn: Try SQL Azure

Cloud computing is now a hot topic, a lot of people have heard of Microsoft's Windows Azure, which is Microsoft's cloud-based operating system, but Microsoft's Azure Services Platform not only the operating system, which is a range of services, but also at least including SQL Azure and Azure Platform AppFabric. Azure Services platform for the upcoming New Year's Day 2010 official business, can now apply for trial its CTP (Customer Technology Preview) version. This article will try SQL Azure to make a brief introduction.

To try SQL Azure, you first need an Invitation Code, you can apply the following URL https://connect.microsoft.com/SQLAzure/SelfNomination.aspx?ProgramID=2089&pageType=1 . As more number of people present application, you may need to wait two or three days to receive the message.

 original.aspx
1 of application page Invitation Code 

With Invitation Code, you can log https://sql.azure.com begin trial. Enter your Invitation Code, you can create your server and database. Creating a server procedure is very simple, as shown in Figure 2, you only need to enter a user password, SQL Azure does not currently support Windows Authentication mode only supports SQL Server authentication.

original.aspx
Figure 2 Creating a server

Creating a database is also very simple, just enter the name of the database and you can select the maximum size of the database click Create Database button in Figure 3, Figure 4. Here we enter testdb, the size of 1GB. SQL Azure supports two versions of the database, called Web version, up to 1GB, when the commercial will charge $ 9.99 per month, and the other called the Business version, up to 10GB, when the commercial will be charged $ 99.99 per month.

original.aspx 
3 database maintenance

 original.aspx
4 Create a database

After creating the database, you need to configure the firewall rules to allow you to access SQL Azure in the server remotely, Figure 5 is an example, I configured the IP address of the start of the 124 can access my server. Firewall rules can not take effect a few minutes, if you can not connect, please wait a while and try again.

original.aspx 
Figure 5 Configure the firewall

After the firewall configuration, you can connect your database from the distal end (to be also used in FIG. 3 Test Connectivity button to confirm the connection). You can use Sqlcmd tool or SSMS, this article will use SSMS example. Do not connect the Object Manager (Object Explorer) when you log in SSMS, SQL Azure because some of view does not exist, the object manager may not work properly (SSMS is my SQL 2008 SP1). New Query directly up the dialog, as shown in Figure 6.

original.aspx 
FIG 6 is connected Dialog

If you want to connect testdb database you just created, you need to click on the Options dialog box is connected (Options >>) button, and choose to connect to testdb in Connection Properties (Connection Properties) tab inside, as shown in FIG. SQL Azure does not support the use of USE testdb to switch the current database. So you must specify the database name, if you do not specify a database name, you will be connected to the master database.

original.aspx 
7 Enter the name of the database you want to connect

In the query window open, you can enter SQL statements to create tables, insert data, or create a stored procedure, execute the stored procedure, and so on. We will execute the following SQL statement creates table1 and insert four data.

CREATE TABLE [dbo].[table1](

      [column1] [int] IDENTITY(1,1) NOT NULL,

      [column2] [varchar](50) NOT NULL,

 CONSTRAINT [PK_table1] PRIMARY KEY CLUSTERED ( [column1] ASC )

)

GO

 

INSERT INTO [dbo].[table1] ([column2]) VALUES ('abcdefg')

INSERT INTO [dbo].[table1] ([column2]) VALUES ('hijklmn')

INSERT INTO [dbo].[table1] ([column2]) VALUES ('opqrst')

INSERT INTO [dbo].[table1] ([column2]) VALUES ('uvwxyz')

GO

After SSMS to create tables and insert data, we can use ADO.NET program to query the data. Here is a simple code we just play the inserted data in the Console. 

SqlConnection conn = new SqlConnection ("Server=tcp:njix2stcmg.database.windows.net;Database=testdb;User ID=shooterlily;Password=;Trusted_Connection=False;Encrypt=True;");

conn.Open();

SqlCommand command = new SqlCommand("select * from dbo.table1", conn);

SqlDataReader reader = command.ExecuteReader();

while (reader.Read())

{

    Console.WriteLine(reader["column1"].ToString() + ":" + reader["column2"].ToString());

}

reader.Close();

conn.Close();

The most important part of this code is that there should be long Connection String, but you do not have to worry about a mistake, you can use the Connection Strings button in Figure 3 to copy, of course, is the need to change the password. Compiler implementation, the results came out. 

original.aspx
8 result of the program of FIG.

This paper briefly describes the process of trial of SQL Azure, interested readers can refer to the links below to learn more.

Reproduced in: https: //www.cnblogs.com/Tim_Liu/archive/2011/01/25/1944522.html

Guess you like

Origin blog.csdn.net/weixin_34080571/article/details/94724538