Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Blank Connection String Issues

Posted on 2011-09-15
5
312 Views
Last Modified: 2012-05-12
I am attempting to use a local file to store the logon information for a ASP.NET site made in C#, and I am getting an empty string returned when I attempt to use the following code to open the connection:

        OracleConnection conn = new OracleConnection();
        conn.ConnectionString = WebConfigurationManager.AppSettings["SampleConnectionString"];
        conn.Open();
After I get to the conn.Open() line of code, I receive a "general error" due to the SampleConnectionString values not being read into the site. The file that contains the connection string has the following line of code within it and is called appsettings.txt:

<appSettings >
      <add key="SampleConnectionString" value="Data Source=WEB;Enlist=false;User ID=user;Password=1234;" />
</appSettings>

Any help that can be provided about why this string, which is included in the project, is not being pulled back into the WebConfigurationManager.AppSettings call would be greatly appreciated.
0
Comment
Question by:thenthorn1010
5 Comments
 
LVL 15

Assisted Solution

by:pateljitu
pateljitu earned 167 total points
ID: 36545300
Please try this:
<connectionStrings>
 <add name="SampleConnectionString" connectionString="Data Source=WEB;Enlist=false;User ID=user;Password=1234;" />
</connectionStrings>

and use this code:
ConfigurationManager.ConnectionStrings["SampleConnectionString"].ConnectionString;
0
 
LVL 14

Assisted Solution

by:binaryevo
binaryevo earned 166 total points
ID: 36545327
System.Configuration.ConfigurationManager.AppSettings["ReportURLLocation"];

Open in new window

 Should get your AppSettings for you.
0
 
LVL 12

Accepted Solution

by:
jagssidurala earned 167 total points
ID: 36545367
instead of

conn.ConnectionString = WebConfigurationManager.AppSettings["SampleConnectionString"];

try this...........

conn.ConnectionString = ConfigurationManager.AppSettings["SampleConnectionString"];

refer these links

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx

http://msdn.microsoft.com/en-us/library/system.web.configuration.webconfigurationmanager.appsettings%28v=VS.80%29.aspx
0
 

Author Comment

by:thenthorn1010
ID: 36545434
jagssidurala,

I did attempt your suggestion and while it does compile, I still end up with a "general" error. Thank you for the suggestion though.
0
 

Author Comment

by:thenthorn1010
ID: 36545498
jagssidurala,

I wanted to apologize...I did find an error in the web.config file that was referencing an invalid location for the appsettings, which would cause the "general error." I did attempt your method and you are correct in the solution to the question I asked.

pateljitu and binaryevo,

I also did verify, after finding the issue in the web.config file, that your methods are valid as well.

All three of you did answer my question completely. Thank you for the help.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question