ตอนที่ 6 : SQL Azure รู้จักกับ Connection String สิทธิ์การใช้งาน SQL Database |
ตอนที่ 5 : SQL Azure รู้จักกับ Connection String และสิทธิ์ในการใช้งาน หลังจากที่เราได้ทำการสร้าง SQL Azure หรือ SQL Database บน Windows Azure เรียบร้อยแล้ว เราจะมาเรียนรู้กฏและเงื่อนไขการใช้งาน SQL Database ว่าจะมีรูปแบบการเรียกใช้งานจาก Application อื่น ๆ ได้อย่างไร และจากบทความก่อน ๆ ตามที่ได้เกรินไว้ SQL Database สามารถรองรับการทำงานร่วมกับ Application ได้อย่างหลากหลาย ไม่ว่าจะเป็นในตระกูลของ .Net Application / PHP / Java และอื่น ๆ
โดยในการใช้งาน SQL Database นั้น Application ที่เรียกใช้งานไไม่จำเป็นจะต้องทำงานอยู่ภายใต้ Service อื่น ๆ ของ Windows Azure เท่านั้น แต่เราสามารถที่จะกำหนดให้สามารถเรียกจากแหล่ง Data Center อื่น ๆ ได้เช่นเดียวกัน แเพียงแต่การที่จะเรียกใช้จาก Data Center อื่น ๆ จะต้องมีการกำหนด Allow IP สำหรับ Application ที่จะทำการ Access เข้ามาใช้ SQL Database ด้วย

Service ของ SQL Database ที่เราได้สร้างขึ้น ในบทความก่อน ๆ หน้านี้

เข้าหน้าหลักของหน้าจอสำหรับการจัดการกับ SQL Database นั้น ๆ ซึ่งจะอยู่ก่อนหน้า Dashboard ให้เราคลิกที่
View SQL Database connection strings for ADO.Net, ODBC, PHP, amd JDBC

Connection String ที่เราจะสามารถนำไปใช้กับ Application ในรูปแบบต่าง ๆ ที่จะพัฒนาขึ้น
ADO.NET:
Server=tcp:bc6hela9fr.database.windows.net,1433;Database=thaicreate-db;User ID=thaicreate-user@bc6hela9fr;Password={your_password_here};Trusted_Connection=False;Encrypt=True;Connection Timeout=30;
ODBC:
Driver={SQL Server Native Client 10.0};Server=tcp:bc6hela9fr.database.windows.net,1433;Database=thaicreate-db;Uid=thaicreate-user@bc6hela9fr;Pwd={your_password_here};Encrypt=yes;Connection Timeout=30;
PHP:
Server: bc6hela9fr.database.windows.net,1433
SQL Database: thaicreate-db
User Name: thaicreate-user
Password={your_password_here}
PHP Data Objects(PDO) Sample Code:
try {
$conn = new PDO ( "sqlsrv:server = tcp:bc6hela9fr.database.windows.net,1433; Database = thaicreate-db", "thaicreate-user", "{your_password_here}");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch ( PDOException $e ) {
print( "Error connecting to SQL Server." );
die(print_r($e));
}
PHP SQL Server Extension Sample Code:
$connectionInfo = array("UID" => "thaicreate-user@bc6hela9fr", "pwd" => "{your_password_here}", "Database" => "thaicreate-db", "LoginTimeout" => 30, "Encrypt" => 1);
$serverName = "tcp:bc6hela9fr.database.windows.net,1433";
$conn = sqlsrv_connect($serverName, $connectionInfo);
JDBC:
jdbc:sqlserver://bc6hela9fr.database.windows.net:1433;database=thaicreate-db;user=thaicreate-user@bc6hela9fr;password={your_password_here};encrypt=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;
เพิ่มเติม
การใช้งานการเชื่อมต่อาจจะสามารถใช้ในรูปแบบอื่น ๆ ได้ แต่เพื่อประสิทธิภาพสูงสุดในการเชื่อมต่อ แนะนำให้ใช้รูปแบบตามที่ไดแจ้งใว้

ในกรณีที่ Application เรียกใช้ภายนอกเหนือจาก Windows Azure จะต้องไปที่ Manage allowed IP addresses

ทำการเพิ่ม IP ที่จะเชื่อมต่อ

ในตัวอย่างจะเป็น IP ที่ต่อจาก ADSL
เพิ่มเติม
ในกรณีที่เราสร้าง Web ไว้บน Web Server ที่ไม่ใช่ Windows Azure แต่จะเรียกใช้ SQL Database เราจะต้อง Allow IP ที่เป็นของ Web Server (ไม่ใช่ Client ที่เรียกใช้ Web)

การ Allow IP จะต้องทำการ SAVE ทุกครั้ง

เมนู HISTORY สามารถที่จะแก้ไข Username และ Password ของ SQL Database ได้

เมนู CONFIGURE จะเห็นในส่วนของ WINDOWS AZURE SERVIES ตัวนี้หมายถึงจะอนุญาติให้ Service ที่อยู่บน Windows Azure สามารถที่จะเรียก SQL Database ตัวนี้ใช้ได้หรือไม่ (ค่าปกติควรจะเป็น Yes)
สำหรับการใช้งาน SQL Database ร่วมกับ Application อื่น ๆ เช่น .NET Application หรือ PHP สามารถที่จะอ่านได้จากหัวข้อถัดไป
อ่านเพิ่มเติม
|