Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 1.0
This is the forum to discuss the Wrox book Beginning ASP.NET 1.0 with C# by Chris Goode, John Kauffman, Christopher L. Miller, Neil Raybould, S. Srinivasa Sivakumar, Dave Sussman, Ollie Cornes, Rob Birdwell, Matt Butler, Gary Johnson, Ajoy Krishnamoorthy, Juan T. Llibre, Chris Ullman; ISBN: 9780764543708
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 7th, 2004, 06:50 AM
Authorized User
 
Join Date: Jul 2004
Location: St. John\'s, NL, Canada.
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object reference Error

Hello,

I am getting this error when I run my code, it complies ok.

 System.NullReferenceException: Object reference not set to an instance of an object

---------------------------
Here is my code for my class:
Imports Microsoft.Win32
Imports System.Data

Public Class clsConnectionString
    Public Function GetConnectionString(ByVal strConnID As String) As String

        'define objects
        Dim objRegistryKey As RegistryKey
        Dim objDatabase As Object

        'define variables
        Dim ConnectionStringArea As String = "SOFTWARE\MyApp\"
        Dim strConnectionPath As String = ConnectionStringArea & strConnID

        'set object to string in registry & return string value
        objRegistryKey = Registry.LocalMachine.OpenSubKey(strConnectionPath , False)
        objDatabase = objRegistryKey.GetValue("strConnID")
        Return Convert.ToString(GetConnectionString(objDatabase))

    End Function

End Class

-------------------------------

I get the error on the "RED" line in my code.

Any help with this is greatly appreciated, I been at this now for 2 days and can get anywhere with it.
Thanks in advance,
Mark


  #2 (permalink)  
Old August 8th, 2004, 04:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

It means that in the Software\MyApp\ folder, it can't find "strConnID" key in the registry. I think you need to specify HKey Local Machine\Software\MyApp

Brian
  #3 (permalink)  
Old August 8th, 2004, 07:58 PM
Authorized User
 
Join Date: Jul 2004
Location: St. John\'s, NL, Canada.
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again Brain,

I think it may have been a typing mistake I my behalf.
The line:
 objRegistryKey = Registry.LocalMachine.OpenSubKey(strConnectionPath , False) lets the program know where the "Software\MyApp" is. My mistake however was there my registry string is called ConnectionSource NOT ConnectionString..

Thanks for your help.

Mark

  #4 (permalink)  
Old August 9th, 2004, 06:39 AM
Authorized User
 
Join Date: Jul 2004
Location: St. John\'s, NL, Canada.
Posts: 71
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Does anyone know what to put in the registry for a connection string, what mean is, how do you type it?

Thanks,
Mark

  #5 (permalink)  
Old August 9th, 2004, 07:29 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Your right, I apologize, I missed that line. Right-click to add a new string value. Enter in the name ConnectionSource, then double-click it and copy/paste your connection string there.

Brian
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Error - Object reference not set to an instance ? venkikrao VB.NET 2 July 5th, 2007 01:00 AM
Class Object reference error. mjhoagland ASP.NET 1.0 and 1.1 Basics 2 February 2nd, 2006 08:28 AM
Error in OleDBConnection : Object reference not se pvsunil Classic ASP Databases 0 April 9th, 2005 02:45 AM
Getting Error - "Object reference not set to an in peri C# 2 December 24th, 2004 10:20 AM
Object reference error shaileshmark SQL Server 2000 2 July 22nd, 2004 03:13 PM



All times are GMT -4. The time now is 09:37 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.