Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Windows Azure > Windows Azure and SQL Azure / SQL Database > ตอนที่ 9 : การเขียน .Net Application ร่วมกับ SQL Database บน Windows Azure



Clound SSD Virtual Server

ตอนที่ 9 : การเขียน .Net Application ร่วมกับ SQL Database บน Windows Azure

ตอนที่ 9 : การเขียน .Net Application ร่วมกับ SQL Database บน Windows Azure การเขียน Application ที่เป็น .NET Framework เพื่อติดต่อกับ SQL Azure หรือ SQL Database นั้น สามารถทำได้ง่ายมาก เพราะถ้าเราเคยเขียนพวก .NET กับ SQL Server ผ่าน NameSpace ของ System.Data.Odbc หรือ System.Data.SqlClient ก็สามารถที่จะเปลี่ยน Application ของเรามาเป็น SQL Azure ได้ง่าย ๆ เพียงการแก้ไขที่ Connection String ท่านั้น ส่วนอื่น ๆ ยังมีรูปแบบการใช้งานเหมือนเดิมทุกประการ โดยสามารถใช้ได้ทั้ง .NET Application ทั้งที่เป็น Web (ASP.Net) , Windows Form (Win App) หรือ Application อื่น ๆ ที่พัฒนาด้วยเทคโนโลยี่ .NET Framework

จากตัวอย่างก่อนหน้านี้เราได้ทำการสร้าง SQL Database บน Windows Azure และทำการเชื่อมต่อพร้อมกับสร้าง Table ขึ้นมา 1 รายการเรียบร้อยแล้ว

ตอนที่ 3 : เชื่อมต่อ SQL Database ผ่าน SQL Server Management Studio (SSMS)


SQL Azure .NET Application

Service ของ SQL Database

SQL Azure .NET Application

Table ชื่อว่า customer

SQL Azure .NET Application

รายการข้อมูลบนตารางของ customer

SQL Database Info
Server Name : bc6hela9fr.database.windows.net
Server : bc6hela9fr
User : thaicreate-user
Password : password@123
Database Name : thaicreate-db









Connection String : ตอนที่ 6 : SQL Azure รู้จักกับ Connection String สิทธิ์การใช้งาน SQL Database


SQL Azure .NET Application

สร้าง Service ของ Web Site เพื่อทดสอบ PHP กับ .NET Web Application

ในการเชื่อมต่อ .NET Application กับ SQL Azure หรือ SQL Database นั้น ในเว็บไซต์ของ Windows Azure ได้แนะนำให้ใช้รูปแบบการเชื่อมต่ออยู่ 2 รูปแบบคือ

รูปแบบที่ 1 : .NET Framework Data Provider for ODBC
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.Odbc"%>
<%@ Page Language="VB" %>
<script runat="server">

	Dim objConn As OdbcConnection
	Dim objCmd As OdbcCommand

	Sub Page_Load(sender As Object, e As EventArgs)
		Dim strConnString As String
		strConnString = "Driver={SQL Server Native Client 10.0};Server=tcp:bc6hela9fr.database.windows.net,1433;Database=thaicreate-db;Uid=thaicreate-user@bc6hela9fr;Pwd=password@123;Encrypt=yes;Connection Timeout=30;"
		objConn = New OdbcConnection(strConnString)
		objConn.Open()

		If objConn.State = ConnectionState.Open Then
			Me.lblText.Text = "SQL Azure/SQL Database Connected"
		Else
			Me.lblText.Text = "SQL Azure/SQL Database Connect Failed"
		End IF
	End Sub

	Sub Page_UnLoad()
		objConn.Close()
		objConn = Nothing
	End Sub

</script>

การใช้งานอื่น ๆ เกี่ยวกับ : System.Data.Odbc


รูปแบบที่ 2 : .NET Framework Data Provider for SQL Server
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="VB" %>
<script runat="server">

	Dim objConn As SqlConnection
	Dim objCmd As SqlCommand

	Sub Page_Load(sender As Object, e As EventArgs)
		Dim strConnString As String
		strConnString = "Server=tcp:bc6hela9fr.database.windows.net,1433;Database=thaicreate-db;User ID=thaicreate-user@bc6hela9fr;Password=password@123;Trusted_Connection=False;Encrypt=True;Connection Timeout=30"
		objConn = New SqlConnection(strConnString)
		objConn.Open()

		If objConn.State = ConnectionState.Open Then
			Me.lblText.Text = "SQL Azure/SQL Database Connected"
		Else
			Me.lblText.Text = "SQL Azure/SQL Database Connect Failed"
		End IF
	End Sub

	Sub Page_UnLoad()
		objConn.Close()
		objConn = Nothing
	End Sub

</script>

การใช้งานอื่น ๆ เกี่ยวกับ : System.Data.SqlClient



Example ตัวอย่างการเขียน ASP.NET Web Application เพื่อติดต่อกับ SQL Database ของ Windows Azure

dotNetWeb.aspx
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="VB" %>
<script runat="server">

	Dim objConn As SqlConnection
	Dim objCmd As SqlCommand

    Sub Page_Load(sender As Object, e As EventArgs)
		Dim strConnString As String
		strConnString = "Server=tcp:bc6hela9fr.database.windows.net,1433;Database=thaicreate-db;User ID=thaicreate-user@bc6hela9fr;Password=password@123;Trusted_Connection=False;Encrypt=True;Connection Timeout=30"
		objConn = New SqlConnection(strConnString)
		objConn.Open()

		BindData()
    End Sub

	Sub BindData()
		Dim strSQL As String
		strSQL = "SELECT * FROM customer"

		Dim dtReader As SqlDataReader
		objCmd = New SqlCommand(strSQL, objConn)
		dtReader = objCmd.ExecuteReader()
		
		'*** BindData to Repeater ***'
		myRepeater.DataSource = dtReader
		myRepeater.DataBind()

		dtReader.Close()
		dtReader = Nothing

	End Sub

	Sub Page_UnLoad()
		objConn.Close()
		objConn = Nothing
	End Sub


</script>
<html>
<head>
<title>ThaiCreate.Com</title>
</head>
<body>
	<form id="form1" runat="server">
    <asp:Repeater id="myRepeater" runat="server">
	<HeaderTemplate>
		<table border="1">
			<tr>
				<th>CustomerID</th>
				<th>Name</th>
				<th>Email</th>
				<th>CountryCode</th>
				<th>Budget</th>
				<th>Used</th>
			</tr>
	</HeaderTemplate>
	<ItemTemplate>
		<tr>
			<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%#Container.DataItem("CustomerID") %>'></asp:Label></td>
			<td><asp:Label id="lblName" runat="server" Text='<%#Container.DataItem("Name") %>'></asp:Label></td>
			<td><asp:Label id="lblEmail" runat="server" Text='<%#Container.DataItem("Email") %>'></asp:Label></td>
			<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%#Container.DataItem("CountryCode") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%#Container.DataItem("Budget") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblUsed" runat="server" Text='<%#Container.DataItem("Used") %>'></asp:Label></td>
		</tr> 		
	</ItemTemplate>
	<AlternatingItemTemplate>
		<tr bgcolor="#e8e8e8">
			<td align="center"><asp:Label id="lblCustomerID" runat="server" Text='<%#Container.DataItem("CustomerID") %>'></asp:Label></td>
			<td><asp:Label id="lblName" runat="server" Text='<%#Container.DataItem("Name") %>'></asp:Label></td>
			<td><asp:Label id="lblEmail" runat="server" Text='<%#Container.DataItem("Email") %>'></asp:Label></td>
			<td align="center"><asp:Label id="lblCountryCode" runat="server" Text='<%#Container.DataItem("CountryCode") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblBudget" runat="server" Text='<%#Container.DataItem("Budget") %>'></asp:Label></td>
			<td align="right"><asp:Label id="lblUsed" runat="server" Text='<%#Container.DataItem("Used") %>'></asp:Label></td>
		</tr>			
	</AlternatingItemTemplate>
	</asp:Repeater>
	</form>
</body>
</html>


SQL Azure .NET Application

FTP ไปไว้บน Web Site

Screenshot

SQL Azure .NET Application








อ่านเพิ่มเติม


   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-05-02 13:04:44 / 2017-03-24 10:57:12
  Download : No files
 Sponsored Links / Related

 
ตอนที่ 1 : รู้จักกับ Service ของ SQL Azure / SQL Database บน Windows Azure
Rating :

 
ตอนที่ 2 : การสร้าง SQL Azure และการใช้งาน SQL Database บน Windows Azure
Rating :

 
ตอนที่ 3 : เชื่อมต่อ SQL Database ผ่าน SQL Server Management Studio (SSMS)
Rating :

 
ตอนที่ 4 : เชื่อมต่อ SQL Azure ผ่าน Microsoft SQL Server Data Tools (SSDT)
Rating :

 
ตอนที่ 5 : การ Backup และ Import Restore บน SQL Azure / SQL Database
Rating :

 
ตอนที่ 6 : SQL Azure รู้จักกับ Connection String สิทธิ์การใช้งาน SQL Database
Rating :

 
ตอนที่ 7 : การใช้งาน SQL Azure ร่วมกับ PHP (SQL Server) (Odbc/sqlsrv/PDO)
Rating :

 
ตอนที่ 8 : เขียน PHP เช่นการ Insert / Update / Delete ข้อมูลบน SQL Database
Rating :

 
ตอนที่ 10 : เขียน .NET แบบ Client Server ติดต่อ SQL Azure / SQL Database
Rating :

 
ตอนที่ 11 : การเขียน Java Application ร่วมกับ SQL Database บน Windows Azure
Rating :

 
ตอนที่ 12 : Example : Java กับ JDBC ติดต่อ SQL Database บน Windows Azure
Rating :

 
ตอนที่ 13 : Example : Java GUI ติดต่อ SQL Database บน Windows Azure
Rating :

 
ตอนที่ 14 : Example : JSP (Java) ติดต่อ SQL Database บน Windows Azure
Rating :

 
ตอนที่ 15 : แหล่งความรู้ SQL Azure / Database ประยุกต์กับการเขียนโปรแกรมต่าง ๆ
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่