[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.odbcnet

Only changed dbase path - now getting Object reference not set

haydnw

9/19/2005 9:36:00 PM


Hi,

I've just changed the server on which my ASP.NET application sits. It's
not terribly complicated, and has been working fine up to now. I've
literally only changed the physical path to the database in the
connection string in web.config, and now the thing is broken! I am
getting the following error message:

[NullReferenceException: Object reference not set to an instance of an
object.]
GetFrontPageInfo.Page_Load(Object Sender, EventArgs E) +529
System.Web.UI.Control.OnLoad(EventArgs e) +67
System.Web.UI.Control.LoadRecursive() +35
System.Web.UI.Page.ProcessRequestMain() +750

which seems to indicate that the problem is with Page_Load. However,
the Page_Load code is different on each page, but a similar error comes
up on every page that accesses the database. That leads me to believe
that it's something to do with the database that's the problem, but I
can't figure out what. :( The code for the page that generates the
above error is shown below. I used to know what this error indicated,
but it's so long since I built the application that I can't remember
now. Any help gratefully received!



That Page_Load code in full..

Public Sub Page_Load(Sender As Object, E As EventArgs)

'Newest album section
'====================

Try

'SQL statement
Dim strSQL as String
strSQL= "SELECT tblEvents.strDirectory, tblEvents.strArtist,
tblEvents.strVenue, tblEvents.strTown, tblEvents.dtmDate FROM tblEvents
INNER JOIN sqyMaxDirOnly ON tblEvents.strDirectory =
sqyMaxDirOnly.strNewestDir;"

'Connection object
objConn = New
OledbConnection(ConfigurationSettings.AppSettings("strConnString"))

'Command object
Dim objNewestCommand As New OledbCommand(strSQL, objConn)

'Data Reader
Dim objNewestDataReader as OledbDataReader

'Open connection and execute command on data reader
objConn.Open()
objNewestDataReader = objNewestCommand.ExecuteReader()

'Set label text to values pulled from database
'Use 'Do While Loop' so that null values are allowed
'(I know there aren't any null values but it gives an error
otherwise!)
Do While objNewestDataReader.Read()=True
lnkNewestAlbumPic.ImageUrl = "../images/newest/" &
objNewestDataReader("strDirectory") & ".jpg"
lnkNewestAlbumPic.NavigateUrl= "album.aspx?d=" &
objNewestDataReader("strDirectory") & "&si=y"
lnkNewestAlbum.NavigateUrl = "album.aspx?d=" &
objNewestDataReader("strDirectory") & "&si=y"
lblstrNewestArtist.text = objNewestDataReader("strArtist")
'Need to use DateTime object to obtain correct formatting,
ie month and year only
dtmDate = objNewestDataReader("dtmDate")
lblstrNewestDate.text = dtmDate.ToString("MMMM yyyy")
Loop

'Close data reader
objNewestDataReader.Close()

Catch Excep As Exception

'Show panel in header for errors and put detail in
pnlError.Visible = True
lblErrorDetail.Text = Excep.ToString()

'Exit Sub
Exit Sub

End Try


'Portfolio image section
'=======================

Try

'SQL statement
Dim strSQL As String
strSQL= "SELECT tblEvents.strDirectory, tblEvents.strArtist,
tblEvents.strVenue, tblEvents.strTown, tblEvents.dtmDate,
tblEvents.strArtistWebsite, sqyRandPortImage.strFilename FROM tblEvents
INNER JOIN sqyRandPortImage ON tblEvents.strDirectory =
sqyRandPortImage.strDirectory;"

'Command object
Dim objPortCommand As New OledbCommand(strSQL, objConn)

'Data Reader
Dim objPortDataReader as OledbDataReader

'Execute command on data reader - connection is already open
objPortDataReader = objPortCommand.ExecuteReader()

'Set label text to values pulled from database
'Use 'Do While Loop' so that null values are allowed
'(I know there aren't any null values but it gives an error
otherwise!)
Do While objPortDataReader.Read()=True
lblstrPortfolioArtist.text =
objPortDataReader("strArtist")
'Need to use DateTime object to obtain correct
formatting, ie month and year only
dtmDate = objPortDataReader("dtmDate")
lblstrPortfolioDate.text = dtmDate.ToString("MMMM
yyyy")
'Set image path
lnkPortfolioImage.ImageUrl = "../images/albums/" &
objPortDataReader("strDirectory") & "/" &
objPortDataReader("strFilename") & ".jpg"
Loop

'Close data reader
objPortDataReader.Close()

Catch Excep As Exception

'Show panel in header for errors and put detail in
pnlError.Visible = True
lblErrorDetail.Text = Excep.ToString()

'Exit Sub
Exit Sub

End Try

End Sub


--
haydnw
------------------------------------------------------------------------
haydnw's Profile: http://www.highdots.com/f...
View this thread: http://www.highdots.com/forum...

1 Answer

Paul Clement

9/20/2005 5:44:00 PM

0

On Mon, 19 Sep 2005 23:36:02 +0200, haydnw <haydnw.1vmm60@no-mx.forums.yourdomain.com.au> wrote:

&#164;
&#164; Hi,
&#164;
&#164; I''ve just changed the server on which my ASP.NET application sits. It''s
&#164; not terribly complicated, and has been working fine up to now. I''ve
&#164; literally only changed the physical path to the database in the
&#164; connection string in web.config, and now the thing is broken! I am
&#164; getting the following error message:
&#164;
&#164; [NullReferenceException: Object reference not set to an instance of an
&#164; object.]
&#164; GetFrontPageInfo.Page_Load(Object Sender, EventArgs E) +529
&#164; System.Web.UI.Control.OnLoad(EventArgs e) +67
&#164; System.Web.UI.Control.LoadRecursive() +35
&#164; System.Web.UI.Page.ProcessRequestMain() +750
&#164;
&#164; which seems to indicate that the problem is with Page_Load. However,
&#164; the Page_Load code is different on each page, but a similar error comes
&#164; up on every page that accesses the database. That leads me to believe
&#164; that it''s something to do with the database that''s the problem, but I
&#164; can''t figure out what. :( The code for the page that generates the
&#164; above error is shown below. I used to know what this error indicated,
&#164; but it''s so long since I built the application that I can''t remember
&#164; now. Any help gratefully received!
&#164;

If the *only* thing you changed was the path to the database then you''re probably encountering a
permissions problem. Where is the file located? Is it on the same machine as the web server?

If your app uses authentication and you''re not using impersonation, does the ASPNET account have
access to the new location?


Paul
~~~~
Microsoft MVP (Visual Basic)