locked
ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString cannot return connection string RRS feed

  • Question

  • Hi,

    I want to use  ConfigurationManager to return my connection string, but I got an error "Object reference not set to an instance of an object."

    The code is

      return (string)System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;

    My MyConnectionString is in the app.config saved in the same folder of cs file that issues the command.

    My application is WCF windows application. I am using vs2010.

    Thanks

     

    Thursday, May 19, 2011 6:20 AM

Answers

  • Hi,

    I found the problem. the configurationManager look at the app.Config under the host project rathr than the current project.

    • Marked as answer by Alan_chen Friday, May 20, 2011 5:39 AM
    Friday, May 20, 2011 3:45 AM

All replies

  • Hi,

    I found the problem. the configurationManager look at the app.Config under the host project rathr than the current project.

    • Marked as answer by Alan_chen Friday, May 20, 2011 5:39 AM
    Friday, May 20, 2011 3:45 AM
  • Hi peter,

    Thanks for your experience here.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 20, 2011 5:40 AM