i have this problem. I use a class called dataserver for my data access.
i create an instance of the class when app starts and call its methods from all my webforms. The code runs well on my devt machine but fails after deployment.
The class goes below
'Option Strict On
Option Explicit Off
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Public Class DataServer
Inherits System.Web.UI.Page
Public Const MAX_PARAM_SIZE = 50
Public gcn As OleDbConnection
Private Const ParamName As String = "@P"
Private mbSuccess As Boolean
Private mds As DataSet
Private mParams() As Object
Public Sub New()
MyBase.New()
ConnectToDatabase()
End Sub
Private Sub ConnectToDatabase()
Dim strConn As String = System.Configuration.ConfigurationSettings.AppSettings("OleDB_ConnectionString")
gcn = New OleDbConnection(strConn)
gcn.Open()
End Sub
Public Function GetData(ByVal ProcName As String, _
ByVal CmdType As CommandType, _
ByVal ParamArray Params() As Object) As DataSet
Dim cmdData As New OleDbCommand
Dim lngU_limit As Integer
Dim lngL_limit As Integer
Dim blnParameterizedQuery As Boolean
Dim dsData As New DataSet
Dim daData As New OleDbDataAdapter
On Error GoTo errh
lngL_limit = LBound(Params, 1)
lngU_limit = UBound(Params, 1)
'If Not lngU_limit <= MAX_PARAM_SIZE Then Exit Function
blnParameterizedQuery = CBool(lngU_limit < MAX_PARAM_SIZE)
With cmdData
.CommandText = ProcName
.CommandType = CmdType
.Connection = gcn
If Not blnParameterizedQuery Then GoTo ExecuteCommand
'Loop thru array contents to append Parameters values
'Note: this method assumes that the client will send the required
'parameters or else a null object reference is returned
Dim pr As OleDbParameter
Dim i As Integer
For i = lngL_limit To lngU_limit
pr = New OleDbParameter
pr.ParameterName = ParamName & i
pr.Value = Params(i)
'pr.OleDbType = OleDbType.VarChar
.Parameters.Add(pr)
pr = Nothing
Next
ExecuteCommand:
daData.SelectCommand = cmdData
daData.Fill(dsData)
GetData = dsData
End With
cmdData = Nothing
Exit Function
errh:
Response.Write(Err.Description)
End Function
Public Function ExecuteProc(ByVal ProcName As String, _
ByVal ParamArray Params() As Object) As Boolean
Dim cmdData As New OleDbCommand
Dim lngU_limit As Integer
Dim lngL_limit As Integer
Dim blnParameterizedQuery As Boolean
On Error GoTo errh
lngL_limit = LBound(Params, 1)
lngU_limit = UBound(Params, 1)
If Not lngU_limit <= 100 Then Exit Function
blnParameterizedQuery = CBool(lngU_limit < 100)
With cmdData
.CommandText = ProcName
.CommandType = CommandType.StoredProcedure
.Connection = gcn
If Not blnParameterizedQuery Then GoTo ExecuteCommand
'Loop thru array contents to append Parameters values
Dim pr As OleDbParameter
Dim i As Integer
For i = lngL_limit To lngU_limit
pr = New OleDbParameter
pr.ParameterName = ParamName & i
pr.Value = Params(i)
.Parameters.Add(pr)
pr = Nothing
Next
ExecuteCommand:
.ExecuteNonQuery()
End With
cmdData = Nothing
Return True
errh:
Return False
End Function
End Class
I then create an instance of this class in Applicatio_onstart
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
'code to read settings from configuration file
On Error Resume Next
Dim sTitle As String = System.Configuration.ConfigurationSettings.AppSettings("AppTitle")
Application("Title") = sTitle
Dim sServer As String = System.Configuration.ConfigurationSettings.AppSettings("ServerName")
Application("ServerName") = sServer
Dim sDBName As String = System.Configuration.ConfigurationSettings.AppSettings("DatabaseName")
Application("DatabaseName") = sDBName
Application("gDataServer") = New DataServer 'new global instance to last the lifetime of app
Dim oSQLDBMO As New SQLDBMO
Dim dt As DataTable
dt = oSQLDBMO.GetProcParameters
Application("Params") = dt
End Sub
i then call the method of the class using latebinding from my webforms
Imports System.Web.UI.WebControls
Imports System.Data
'Imports System.Data.OleDb
Imports System.Web.SessionState
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Agents
Inherits System.Web.UI.Page
Private mbSuccess As Boolean
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents grdAgents As System.Web.UI.WebControls.DataGrid
#End Region
Private dsAgent As DataSet
Private bSuccess As Boolean
Private sPriv As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
LoadData()
BindGrid(grdAgents)
End If
End Sub
Private Sub LoadData()
Dim mparams(50)
dsAgent = Application("gDataserver").Getdata("Select * from Agents", CommandType.Text, mparams)
grdAgents.DataSource = dsAgent
grdAgents.DataBind()
End Sub
End Class
When i run the app after deployment it returns the following error about latebinding
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Response is not available in this context.]
Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) +899
Metric.Agents.LoadData() in C:\Inetpub\wwwroot\Metric\Agents.aspx.vb:93
Metric.Agents.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Metric\Agents.aspx.vb:77
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731
i create an instance of the class when app starts and call its methods from all my webforms. The code runs well on my devt machine but fails after deployment.
The class goes below
'Option Strict On
Option Explicit Off
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports Microsoft.VisualBasic
Public Class DataServer
Inherits System.Web.UI.Page
Public Const MAX_PARAM_SIZE = 50
Public gcn As OleDbConnection
Private Const ParamName As String = "@P"
Private mbSuccess As Boolean
Private mds As DataSet
Private mParams() As Object
Public Sub New()
MyBase.New()
ConnectToDatabase()
End Sub
Private Sub ConnectToDatabase()
Dim strConn As String = System.Configuration.ConfigurationSettings.AppSettings("OleDB_ConnectionString")
gcn = New OleDbConnection(strConn)
gcn.Open()
End Sub
Public Function GetData(ByVal ProcName As String, _
ByVal CmdType As CommandType, _
ByVal ParamArray Params() As Object) As DataSet
Dim cmdData As New OleDbCommand
Dim lngU_limit As Integer
Dim lngL_limit As Integer
Dim blnParameterizedQuery As Boolean
Dim dsData As New DataSet
Dim daData As New OleDbDataAdapter
On Error GoTo errh
lngL_limit = LBound(Params, 1)
lngU_limit = UBound(Params, 1)
'If Not lngU_limit <= MAX_PARAM_SIZE Then Exit Function
blnParameterizedQuery = CBool(lngU_limit < MAX_PARAM_SIZE)
With cmdData
.CommandText = ProcName
.CommandType = CmdType
.Connection = gcn
If Not blnParameterizedQuery Then GoTo ExecuteCommand
'Loop thru array contents to append Parameters values
'Note: this method assumes that the client will send the required
'parameters or else a null object reference is returned
Dim pr As OleDbParameter
Dim i As Integer
For i = lngL_limit To lngU_limit
pr = New OleDbParameter
pr.ParameterName = ParamName & i
pr.Value = Params(i)
'pr.OleDbType = OleDbType.VarChar
.Parameters.Add(pr)
pr = Nothing
Next
ExecuteCommand:
daData.SelectCommand = cmdData
daData.Fill(dsData)
GetData = dsData
End With
cmdData = Nothing
Exit Function
errh:
Response.Write(Err.Description)
End Function
Public Function ExecuteProc(ByVal ProcName As String, _
ByVal ParamArray Params() As Object) As Boolean
Dim cmdData As New OleDbCommand
Dim lngU_limit As Integer
Dim lngL_limit As Integer
Dim blnParameterizedQuery As Boolean
On Error GoTo errh
lngL_limit = LBound(Params, 1)
lngU_limit = UBound(Params, 1)
If Not lngU_limit <= 100 Then Exit Function
blnParameterizedQuery = CBool(lngU_limit < 100)
With cmdData
.CommandText = ProcName
.CommandType = CommandType.StoredProcedure
.Connection = gcn
If Not blnParameterizedQuery Then GoTo ExecuteCommand
'Loop thru array contents to append Parameters values
Dim pr As OleDbParameter
Dim i As Integer
For i = lngL_limit To lngU_limit
pr = New OleDbParameter
pr.ParameterName = ParamName & i
pr.Value = Params(i)
.Parameters.Add(pr)
pr = Nothing
Next
ExecuteCommand:
.ExecuteNonQuery()
End With
cmdData = Nothing
Return True
errh:
Return False
End Function
End Class
I then create an instance of this class in Applicatio_onstart
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
'code to read settings from configuration file
On Error Resume Next
Dim sTitle As String = System.Configuration.ConfigurationSettings.AppSettings("AppTitle")
Application("Title") = sTitle
Dim sServer As String = System.Configuration.ConfigurationSettings.AppSettings("ServerName")
Application("ServerName") = sServer
Dim sDBName As String = System.Configuration.ConfigurationSettings.AppSettings("DatabaseName")
Application("DatabaseName") = sDBName
Application("gDataServer") = New DataServer 'new global instance to last the lifetime of app
Dim oSQLDBMO As New SQLDBMO
Dim dt As DataTable
dt = oSQLDBMO.GetProcParameters
Application("Params") = dt
End Sub
i then call the method of the class using latebinding from my webforms
Imports System.Web.UI.WebControls
Imports System.Data
'Imports System.Data.OleDb
Imports System.Web.SessionState
Imports System.IO
Imports Microsoft.VisualBasic
Public Class Agents
Inherits System.Web.UI.Page
Private mbSuccess As Boolean
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents grdAgents As System.Web.UI.WebControls.DataGrid
#End Region
Private dsAgent As DataSet
Private bSuccess As Boolean
Private sPriv As String
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
LoadData()
BindGrid(grdAgents)
End If
End Sub
Private Sub LoadData()
Dim mparams(50)
dsAgent = Application("gDataserver").Getdata("Select * from Agents", CommandType.Text, mparams)
grdAgents.DataSource = dsAgent
grdAgents.DataBind()
End Sub
End Class
When i run the app after deployment it returns the following error about latebinding
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Response is not available in this context.]
Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack) +899
Metric.Agents.LoadData() in C:\Inetpub\wwwroot\Metric\Agents.aspx.vb:93
Metric.Agents.Page_Load(Object sender, EventArgs e) in C:\Inetpub\wwwroot\Metric\Agents.aspx.vb:77
System.EventHandler.Invoke(Object sender, EventArgs e) +0
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +731