รูปแบบที่ 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>
รูปแบบที่ 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>