Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9176451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:06:40+00:00 2026-06-17T17:06:40+00:00

Using Visual Studio 2012 which was recently installed but now I can’t connect to

  • 0

Using Visual Studio 2012 which was recently installed but now I can’t connect to our SQL Server database.

These are the steps I’m following

  1. create App1.config
  2. type this in App1.config:

     <?xml version="1.0" encoding="utf-8" ?>
     <configuration>
       <connectionStrings>
         <add name ="xxx" connectionString="USER ID=xx;PASSWORD=xx;PERSIST SECURITY INFO=True;Data Source=xx;Initial Catalog=xx" />
       </connectionStrings>
     </configuration>
    
  3. Add a reference to the project to System.Configuration

  4. Create access to namespaces via:

     using System.Data.SqlClient;
     using System.Data;
     using System.Configuration;
    
  5. implement the following:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Data.SqlClient;
    using System.Data;
    using System.Configuration;
    
    namespace ConsoleApplication10 {
        class Program {
            static void Main(string[] args) {
    
                SqlConnection conn = null;
                conn = new SqlConnection(ConfigurationManager.ConnectionStrings["xxx"].ConnectionString);
    
            }
        }
    }
    
  6. I’ve created a new console app and added the above and I still get an error NullReferenceException was unhandled Object reference not set to an instance of an object. …

enter image description here

EDIT

Via the immediate window I determined that the following is null:

ConfigurationManager.ConnectionStrings["xxx"].ConnectionString

If I hard-code the connection string into the constructor for SqlConnection then it connects ok

What am I missing – something really obvious!! Or is this in connection with my new VS ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:06:42+00:00Added an answer on June 17, 2026 at 5:06 pm

    check what is in the ConfigurationManager.ConnectionStrings by excecuting at least the following:

    if (ConfigurationManager.ConnectionStrings != null ) {
        Console.WriteLine(ConfigurationManager.ConnectionStrings.Count);
        Console.WriteLine(ConfigurationManager.ConnectionStrings[0].ConnectionString);
        Console.WriteLine(ConfigurationManager.ConnectionStrings[0].Name);
        ....
    } else {
        Console.WriteLine("null");
    }
    

    This will highlight any obvious problems like duplication of the App.config file which could well be the case as you mentioned App1.config in the OP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Visual studio 2011 beta with the april 2012 update installed .I
I am using Visual Studio 2010 and I installed Microsoft Report Viewer 2012 Runtime
My team has recently converted to Visual Studio 2012 and is using the Code
Using the Visual Studio Nov 2012 CTP, which supports variadic templates (among other things).
I am using Visual Studio 2012 (v11) which is using a version of MFC
I've recently downloaded and installed Windows 8 OS along with Visual Studio 2012 and
So I`m using Visual Studio 2012 and have application, which creates notifyIcon and show
I'm currently learning ASP.Net MVC; I'm using Visual Studio Express 2012 with MVC4 (which
I'm using Visual Studio 2012 and am using a solution which contains some unit
Started using Visual Studio 2012 RC since yesterday, We have one WCF solution. Whenever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.