CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2007
    Posts
    115

    configurationmanager.connection string giving System.NullReferenceException was unhan

    Dear Sir,

    I am in great trouble, I have a project on visual studio 2008 and I getting connectionstring using ConfigurationManager.ConnectionStrings("connestionstring").ConnectionString. this project have a app.config file which contain
    /code
    <connectionStrings>
    <add name="RMINVENTORY" connectionString="Server=localhist;Initial Catalog=Northwind;Integrated Security=SSPI" />
    </connectionStrings
    I get the connection using str variable like this
    dim str as string
    str=ConfigurationManager.ConnectionStrings("RMINVENTORY").ConnectionString

    code/

    In visual 2008 it works perfectly, but in 2010 it giving the error like this
    "System.NullReferenceException was unhandled
    Message=Object reference not set to an instance of an object.
    Source=Inventory.Metadata"

    Please help where is the problem

    Thanking You

    Debasis Bag

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: configurationmanager.connection string giving System.NullReferenceException was u

    Because it's not a string. It is a ConnectionString(). Press F1 for HELP! .ToString will convert it, but it won't work.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: configurationmanager.connection string giving System.NullReferenceException was u

    Where does the code blow up at? The message does not seem to point to the code you have shown so I have no idea where yuour problem may be. Run it in debug mode and see what line is executing when the error is generated.
    Always use [code][/code] tags when posting code.

  4. #4
    Join Date
    May 2012
    Location
    Foxboro
    Posts
    1

    Re: configurationmanager.connection string giving System.NullReferenceException was u

    I would say that the web.config file doesn't contain your connection string (check for spelling errors)

  5. #5
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: configurationmanager.connection string giving System.NullReferenceException was u

    Quote Originally Posted by Debasis Bag View Post
    <add name="RMINVENTORY" connectionString="Server=localhist;Initial Catalog=Northwind;Integrated Security=SSPI" />
    Should that not be Localhost...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured