Monday, March 26, 2012
Object reference not set to an instance of an object
I have a .NET DLL which I am trying to call from an ASP .NET application. The DLL errors (Object reference not set to an instance of an object) when using a function from another DLL which is instantiated once successfully.
This DLL works perfectly when called from a VB.NET application.
ASP.NET:
Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
Dim objProgram As New WCS_DLL_Interface_Girobank_Split.WCS_DLL_Interface_Girobank_Split
objProgram.Run("040927", "C:\Inetpub\wwwroot\WCS_ASP_Interface_BulkPayments\App.config")
End If
End Sub
VB.NET DLL:
'Successfully creates instance
Dim objDB As New WCS_db_authentication.db
'Loop
'Error Line
strRAN = objDB.getData_ID(strAppPath, "WCS_SP_TMP_Girobank_Split_FindDebt", strWCS_SP_TMP_Girobank_Split_FindDebt)
'End Loop
I can't see why this would work in VB.NET and not ASP.NET. It creates the object fine (Even debugging "objDB is null" returns false).
Any one any ideas?
Cheers...what is the code for WCS_db_authentication.db
Woka
Originally posted by Wokawidget
what is the code for WCS_db_authentication.db
Woka
Seems it was a problem with a database function in wcs_db_authentication after all. Didn't have the correct permissions to connect.
Thanks for the reply.
Saturday, March 24, 2012
Object reference not set to an instance of an object
So its not the contents that are causing this, just the fact that the function cannot be found. Almost as if the new dll is not being used.
Any help greatly accepted.
RichardPlease check if you had placed the dll's in the correct folders or not
Thanks,
Only one dll, and it goes in the bin directory, any other ideas?
Friday, March 16, 2012
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
Here's my code, this is in the functions.cs page:
using System;
using System.Text;
namespace web_isotope.functions
{
public class mainFunctions : System.Web.UI.UserControl
{
public string pageStatus()
{
error-->string strURL = Request.ServerVariables["URL"];
StringBuilder replaceFunc = new StringBuilder(strURL);
strURL = replaceFunc.Replace("/web_isotope/","").ToString();
strURL = replaceFunc.Replace(".aspx","").ToString();
return strURL;
}
}
}
I want to be able to call it from the home.aspx.cs page
Does anyone know why I'm getting this error?
Thanks in advance!You can't request server variables from a .cs file. you might need to use the Request.ServerVariables () function in you .aspx file and then pass that value to the function...
like so:
in your .aspx file
string strURL = Request.ServerVariables["URL"];
mainFunctions objMainFunctions = new mainFunctions();
objMainFunctions.pageStatus(strURL);
and in your .cs
public string pageStatus(p_strURL)
{
StringBuilder replaceFunc = new StringBuilder(p_strURL);
///...
The error is due to the fact that Control doesn't contain a definition of the Request Object. It does, however, define Page (which is the Page that contains the Control) and so you can use Page.Request.ServerVariables["URL"].
I would question why you are inheriting from System.Web.UI.UserControl and how are you instantiating the Control in your code?
Object reference not set to an instance of an object.
Can anyone please point out what is causing this error!
I am trying to call a function then read its dataset
rgs
Tony
Server Error in '/' Application.
------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
<code/
Dim dataSet As System.Data.DataSet
Sub Button1_Click(sender As Object, e As EventArgs)
dim ida as string = textbox1.text
call MyQueryMethod(ida)
dim text as string = dataset.tables(0).rows(0).item(0)
response.write(text)
End Sub
Function MyQueryMethod(ByVal iD As Integer) As System.Data.DataSet
Dim connectionString As String = "server=xxxx.xxx.xxx; user id=xxxxx.150'; password=xxxxxx; database=xxxx"& _
"xxxxxx.150'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [tblReg].[UserName] FROM [tblReg] WHERE ([tblReg].[ID] = @dotnet.itags.org.ID)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_iD As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_iD.ParameterName = "@dotnet.itags.org.ID"
dbParam_iD.Value = iD
dbParam_iD.DbType = System.Data.DbType.Int32
dbCommand.Parameters.Add(dbParam_iD)
Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.SqlClient.SqlDataAdapter
dataAdapter.SelectCommand = dbCommand
Dim dataSet As System.Data.DataSet = New System.Data.DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
</code>
call MyQueryMethod(ida)Looks like you want to change that todim text as string = dataset.tables(0).rows(0).item(0)
dim text as string = MyQueryMethod(ida).tables(0).rows(0).item(0)