Solved

Blank Connection String Issues

Posted on 2011-09-15
5
319 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
[X]
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
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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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