Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Blank Connection String Issues

Posted on 2011-09-15
5
Medium Priority
?
323 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 668 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 664 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 668 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
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!
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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