SQL Azure - Bapatla Engineering College

Download Report

Transcript SQL Azure - 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.
 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.
SQL Azure Database Access
 To access a SQL Azure database from the Microsoft .NET
Framework code, you can use standard ADO.NET: the
SqlCommand class to define a command, a SqlDataReader
to pull data out, or SqlDataAdapter, because internally SQL
Azure uses a SqlDataReader in a traditional manner.
 You only have to adapt the SqlConnection class’s
connection string. After you change it to the cloud version
of the server, you just log on.
SQL Azure Database Access
 Example
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
SQL Azure Database Access
 Example
namespace TAServices{
public partial class _Default :
System.Web.UI.Page{
protected void Page_Load(object
sender, EventArgs e){
try{
using (SqlConnection conn = new
SqlConnection()){
conn.ConnectionString =
"someconnectionstring";
SQL Azure Database Access
 Example
using (SqlCommand cmd = new SqlCommand()){
cmd.Connection = conn;
cmd.CommandText = "SELECT CustomerID
from customers";
conn.Open();
using (SqlDataReader dr =
cmd.ExecuteReader(CommandBehavior.CloseConnect
ion)){
while (dr.Read()){
// Do something
}
SQL Azure Database Access
 Example
dr.Close();
}
}
}
}
catch (SqlException ex){
// Something goes wrong
}
}
}
}
SQL Azure Database Access
 Example
dr.Close();
}
}
}
}
catch (SqlException ex){
// Something goes wrong
}
}
}
}
SQL Azure Database Access
 Connection String Examples
 Classic Connection connection string for a trusted SQL
connection
Server=myServer;Database=myDb;
Trusted_Connection=Yes;
 If you are using a standard SQL connection instead of a
trusted one, you have to modify the connection as
shown in the following code:
Server=myServer;Database=myDb;
Trusted_Connection=Yes;
User ID=user;Password=password;
Trusted_Connection=False;
SQL Azure Database Access
 Connection String Examples
 Connection String for Entity Framework
metadata=res://*/
Model.csdl|res://*/
DataModel.ssdl|res://*/DataModel.msl;
provider=System.Data.SqlClient;
provider connection
string="Data
Source=VirtualServerName.database.windows.net;
Initial
Catalog=MyDB;Integrated
Security=False;
User ID=user@VirtualServerName;
Password=password;
MultipleActiveResultSets=False;
Encrypt=True;TrustServerCertificate=False""
providerName="System.Data.EntityClient"
SQL Azure Database Access
 Code to Access SQL Azure Database using java
hibernate.connection.driver_class=com.microsoft
.sqlserver.jdbc.SQLServerDriver
hibernate.connection.url=jdbc:sqlserver://Virtu
alServerName.database.windows.net:1433;
databaseName=mydb
hibernate.connection.username=user@VirtualServe
rName
hibernate.connection.password=password
SQL Azure Database Access
 Code to Access SQL Azure Database using PHP
$server =
"tcp:VirtualServerName.database.windows.net,1433
";
$user = "User@VirtualServerName";
$pass = "password";
$database = "MyDB";
$connectionoptions = array("Database" =>
$database,
"UID" => $user,
"PWD" => $pass,
"MultipleActiveResultSets" => false);
$conn = sqlsrv_connect($server,
$connectionoptions);