My questions is very simple (I think) I'd like your opinion where to open the DB connection. In classic ASP I'd open the connection near the top of the page where I'd need it and close it with the last trip to the DB near the bottom of the page. I'd only have 1 connection per page.
Can I, should I use the same scenario in .NET ? So far I'm using something like this: (2 connections per page)
"Taxes are the fees we pay for civilized society" G.W.
Can I, should I use the same scenario in .NET ? So far I'm using something like this: (2 connections per page)
Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack = True Then
Call BindData()
End If
End Sub
Sub BindData()
Dim myConnection As System.Data.SqlClient.SqlConnection
Dim myCommand As System.Data.SqlClient.SqlDataAdapter
Dim SQL As String = "SELECT fldUSERNAME, fldIP, fldDATE FROM tbl_adminlogs ORDER BY ID DESC"
myConnection = New System.Data.SqlClient.SqlConnection(ConnectionString)
myCommand = New System.Data.SqlClient.SqlDataAdapter(SQL, myConnection)
Dim ds As DataSet = New DataSet()
myCommand.Fill(ds)
dGrid.DataSource = ds
dGrid.DataBind()
myConnection.Close()
myConnection.Dispose()
lblTotal.Text = "Total Entries Found: " & Return_TotalC.ToString
End Sub
Sub NewPage(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
dGrid.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
Function Return_TotalC() As Int32
Dim strConn As String = ConnectionString
Dim strSQL As String = "SELECT COUNT(ID) FROM tbl_adminlogs"
Dim Conn As New System.Data.SqlClient.SqlConnection(strConn)
Dim Cmd As New System.Data.SqlClient.SqlCommand(strSQL, Conn)
Conn.Open()
Return_TotalC = Cmd.ExecuteScalar()
Conn.Close()
Conn.Dispose()
End Function
"Taxes are the fees we pay for civilized society" G.W.