Solved

Problem reading app.config file

Posted on 2006-11-16
8
337 Views
Last Modified: 2010-04-23
I have a user control that started by retrieving connection entry from a registry entry.  I created a form that uses the version of the control that read the connection from the registry.   I then changed the control to read the connection setting from an app.config file.   The application seemed fine.

Now when I try to create a new form using the user control by dragging and droping the usercontrol from the toolbox, I'm getting a msgbox with an error saying Error retrieving connection string from configuration file in BaseDAL.vb file and the control is not added to the form.

After putting in countless msgboxes I found where the problem is happening.......

           Dim strConnectionString As String

            strConnectionString = ConfigurationSettings.AppSettings("ConnectionString")

            MsgBox(strConnectionString)

            If strConnectionString <> "" Then
                m_sConnekStrg = strConnectionString
            Else
                Throw New Exception("Error retrieving connection string from configuration file in BaseDAL.vb file.")
            End If

The messagebox displays with blanks which tells me the app file is not being read correctly

I can see the control appear in the form.  when I click ok, the control disappears from the form and the
Error retrieving connection string from configuration file in BaseDAL.vb file appears.


Not sure why this is happening....


App file is read fine in the form containing the control before I made the change from reading from registry.   Doesn't if I try to put updated control on a new form.


any ideas?
0
Comment
Question by:johnnyg123
[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
  • 3
8 Comments
 

Author Comment

by:johnnyg123
ID: 17960464
Here is the config file

The app is named customer so the file name is

Customer.exe.config and located in the /bin folder of the app exe




<?xml version="1.0" encoding="utf-8"?>
<configuration>
      <appSettings>

 <add key="ConnectionString" value="Persist Security Info=True;User ID=cust_app;Password=custapp;Initial Catalog=CustomerInfo;Data Source=webprd01;Application Name=Customer Info Tracking;Connect Timeout=60"/>
 <add key="LastUpdated" value="10/12/06"/>

 </appSettings>
</configuration>
0
 

Author Comment

by:johnnyg123
ID: 17960938
if I  set strConnectionString  to the string in the config file it works fine.   is it possible the config file should be in multiple places?


please...please  help


I've spent way to0 much time on this
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17962748
This is the limitation of app.config file that it should lie under executable path, now when your user control integrates with an parent application, it going to read parent config not the one which of user control, so you have to make rConnectionString  part  of parent config file.

Meanwhile you can try using
ConfigurationManager.OpenExeConfiguration()
command by giving path so that it picks user control config file, lets see if it works????
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:johnnyg123
ID: 17966786
unfortunately, not familiar with ConfigurationManager.OpenExeConfiguration()


Can you please give me an example?

I would replace

 Dim strConnectionString As String

            strConnectionString = ConfigurationSettings.AppSettings("ConnectionString")

            MsgBox(strConnectionString)

            If strConnectionString <> "" Then
                m_sConnekStrg = strConnectionString
            Else
                Throw New Exception("Error retrieving connection string from configuration file in BaseDAL.vb file.")
            End If


0
 
LVL 5

Accepted Solution

by:
DEEPESH earned 500 total points
ID: 17970527
ok first try this
 Dim config As System.Configuration.Configuration
        config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
        Dim value As String
        value = ConfigurationManager.AppSettings(TextBox1.Text)
        MsgBox(value)


and if it not works then use this

        Dim config As System.Configuration.Configuration
        config = ConfigurationManager.OpenExeConfiguration("C:\Documents and Settings\Administrator\Desktop\DOTNETAPP\WinAppl\WindowsConsumeApplication\app.config")
        Dim value As String
        value = ConfigurationManager.AppSettings("a")
        MsgBox(value)
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17970705
Hi Johnnyg have you tried this
0
 

Author Comment

by:johnnyg123
ID: 17980878
I am getting a type exepected error  in the

Dim config As System.Configuration.Configuration


I have


Imports System
Imports System.Configuration
Imports Microsoft.Win32
Imports System.Data.SqlClient
Imports System.Convert
Imports System.Object
Imports System.Collections
Imports System.Data.DataSet
Imports System.XML
Imports System.IO


Am I missing something?
0
 

Author Comment

by:johnnyg123
ID: 17990406
Deepesh,

Thanks for your input.


I found a hack work around but wanted to acknowledge your contributions.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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…
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…

735 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