Solved

Blank Connection String Issues

Posted on 2011-09-15
5
310 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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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