Reading from web configuration file

vensali
vensali used Ask the Experts™
on
I can read connection string from webconfig file  from visual studio from the below mentioned code
in login.aspx page

 Private constr As String
    Private rootWebConfig As System.Configuration.Configuration
    Private connString As System.Configuration.ConnectionStringSettings

rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/WEBUI")    where WEBUI is project folder where webconfig resides.

        connString = rootWebConfig.ConnectionStrings.ConnectionStrings("Sqlserver")
        constr = connString.ConnectionString

I created  web deploy package and imported into localhost IIS 7. import application worked fine. when I tried to browse the login.aspx from IIS published folder I get the following msg

Server Error in '/KHWEB' Application.  -  KHWEB  web application name in IIS7

Object reference not set to an instance of an object.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
jorge_torizResearch & Development Manager

Commented:
Can you try with the following change?

OpenWebConfiguration("./WEBUI")
Commented:
I could solve the problem by giving   my web application name ( "/ App name")  hosted in iis in open configuration.

Author

Commented:
I could solve the problem by giving   my web application name ( "/ App name")  hosted in iis in open configuration.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial