Windows Azure SQL Database - Bapatla Engineering College
Download
Report
Transcript Windows Azure SQL Database - Bapatla Engineering College
SQL Azure Database
Windows Azure SQL Database is a feature-rich, fully
managed relational database service that offers a highly
productive experience, incorporates proven SQL Server
technology, and delivers business-class capabilities.
SQL Database allows customers to scale business apps for
burst and global reach by removing the high costs of
building an infrastructure which would accommodate
occasional peak loads.
SQL Azure Database
Customers can also remove the security risks and hassles
associated with hosting public-facing apps & websites from
within a datacenter by quickly & cost-effectively building
websites and mobile & social apps directly on SQL
Database.
Step 1: Create a Windows Azure account
Open
a
web
browser,
and
browse
to
http://www.windowsazure.com. To get started with a
free account, click free trial in the upper right corner
and follow the steps.
Your account is now created. You are ready to get
started.
Step 2: Connect to Windows Azure and create a
database
Sign in to the Management Portal. You should see a
navigation pane that looks like this.
Click New at the bottom of the page. When you click
New, a list rolls up the screen showing things you can
create.
Click SQL Database and then click Custom Create.
Choosing this option lets you create a new server at the
same time, with you as the administrator. As the
system administrator, you can perform more tasks,
including connecting to the Management Portal for
SQL Database, which you will do later in this tutorial.
The Database Settings page appears when you click
Custom Create. In this page, you provide basic
information that creates an empty database on the
server. Adding tables and data will come in a later step.
Fill out the Database Settings page as follows:
Step 3: Configure the firewall
To configure the firewall so that connections are
allowed through, you'll enter information on the server
page.
Note: The SQL Database service is only available with
TCP port 1433 used by the TDS protocol, so make sure
that the firewall on your network and local computer
allows outgoing TCP communication on port 1433. For
more information, see SQL Database Firewall.
In the navigation pane on the left, click SQL
Databases.
Click Servers at the top of the page. Next, click on the
server you just created so that you see a white arrow to
the right. Click on the arrow to open the server page.
Copy the current client IP address. This is the IP address that
your router or proxy server is listening on. SQL Database
detects the IP address used by the current connection so that
you can create a firewall rule to accept connection requests
from this device.
Paste the IP address into both the beginning and end range.
Later, if you encounter connection errors indicating that the
range is too narrow, you can edit this rule to widen the range.
Enter a name for the firewall rule, such as the name of your
computer or company.
Click the checkmark to save the rule.
After you save the rule, your page will look similar to the
following screenshot.
To create a table and add data follow the steps next
using
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;
System.Data.SqlClient;
System.Data;
private static string userName =
"SQLServer";
private static string password =
"gsmenergy@123";
private static string dataSource =
"gct870i4ka.database.windows.net";
private static string sampleDatabaseName
= "ContactsDB";
SqlConnectionStringBuilder connString1Builder;
connString1Builder = new
SqlConnectionStringBuilder();
connString1Builder.DataSource =
dataSource;
connString1Builder.InitialCatalog =
"ContactsDB";
connString1Builder.Encrypt = true;
connString1Builder.TrustServerCertificate = false;
connString1Builder.UserID = userName;
connString1Builder.Password = password;
using (SqlConnection conn = new
SqlConnection(connString1Builder.ToString()))
{
using (SqlCommand command = conn.CreateCommand())
{
conn.Open();
command.CommandText = "SELECT * FROM contacts";
using (SqlDataReader reader = command.ExecuteReader())
{
// Loop over the results
while (reader.Read())
{
Console.WriteLine("{0}, {1}, {2}, {3}“,
reader["ID"].ToString(),reader["FirstName"].
ToString(), reader["LastName"].ToString(),
reader["ContactNO"].ToString());
}
}
Console.ReadKey();
conn.Close();
}
}