Solved

Blank Connection String Issues

Posted on 2011-09-15
5
305 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Asp/Net Validation date Issue 9 36
Pass through dll 2 33
comparing string in C# 3 32
C# SQL BULK INSERT CLASS 5 33
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now