一步一步 Sql Azure

來源:互聯網
上載者:User

                      一步一步    Sql Azure  

1.      使用 windowsazure 平台帳號登陸 https://windows.azure.com/

2.      建立Sql Azure Server

 

3.      建立資料庫

 

4.      為Sql azure server 添加防火牆規則,只有將本機添加到規則裡才能從本機串連到該Sqlazure server

5.      串連到Sql azure server

輸入建立Sql Azure Server時定義的使用者名稱和密碼

6.      建立表

7.      向表中填充資料

 

 

8.      使用代碼訪問Sql Azure 中的資料

 

附訪問Sql Azure 資料庫的主要代碼:

 Default.aspx.cs:

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Microsoft.WindowsAzure;using Microsoft.WindowsAzure.StorageClient;using Microsoft.WindowsAzure.ServiceRuntime;using System.Threading;using System.Data.SqlClient;using System.Data;namespace WebRole1{    public partial class _Default : System.Web.UI.Page    {        private static string userName = "yourSqlAzureUsernam";        private static string password = "yourSqlAzureUserPassword";        private static string dataSource = "yourSqlAzureServerName.database.windows.net";        private static string sampleDatabaseName = "AzureDB";        protected void Page_Load(object sender, EventArgs e)        {            if (!this.IsPostBack)            {                                SqlConnectionStringBuilder connStringBuilder = new SqlConnectionStringBuilder();                connStringBuilder.DataSource = dataSource;                connStringBuilder.InitialCatalog = sampleDatabaseName;                connStringBuilder.Encrypt = true;                connStringBuilder.TrustServerCertificate = false;                connStringBuilder.UserID = userName;                connStringBuilder.Password = password;                using (SqlConnection conn = new SqlConnection(connStringBuilder.ToString()))                {                    using (SqlCommand command = conn.CreateCommand())                    {                        // Create the AzureDB                        string cmdText = "select * from dbo.Person";                        command.CommandText = cmdText;                        SqlDataAdapter dataApater = new SqlDataAdapter(command);                        DataSet dataSet = new DataSet();                        dataApater.Fill(dataSet);                        GridView1.DataSource = dataSet.Tables[0].DefaultView;                        GridView1.DataBind();                    }                }            }        }           }}

Default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebRole1._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title></head><body>    <form id="form1" runat="server">    <div>            <asp:GridView ID="GridView1" runat="server" CellPadding="4"             EnableModelValidation="True" ForeColor="#333333" GridLines="None">            <AlternatingRowStyle BackColor="White" />            <Columns>                <asp:CommandField ButtonType="Button" HeaderText="select" ShowHeader="True"                     ShowSelectButton="True" />            </Columns>            <EditRowStyle BackColor="#2461BF" />            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />            <RowStyle BackColor="#EFF3FB" />            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />        </asp:GridView>        <br />        <asp:DetailsView ID="DetailsView1" runat="server" CellPadding="4"             EnableModelValidation="True" ForeColor="#333333" GridLines="None" Height="50px"             Width="265px">            <AlternatingRowStyle BackColor="White" />            <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />            <EditRowStyle BackColor="#2461BF" />            <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />            <RowStyle BackColor="#EFF3FB" />        </asp:DetailsView>        <br />        <br />          </form></body></html>

 

如何建立並部署雲應用程式,請參考

http://blog.csdn.net/farawayplace613/article/details/6933915

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.