johnnyg123
asked on
Problem reading app.config file
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.AppS ettings("C onnectionS tring")
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?
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.AppS
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?
ASKER
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
please...please help
I've spent way to0 much time on this
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.OpenE xeConfigur ation()
command by giving path so that it picks user control config file, lets see if it works????
Meanwhile you can try using
ConfigurationManager.OpenE
command by giving path so that it picks user control config file, lets see if it works????
ASKER
unfortunately, not familiar with ConfigurationManager.OpenE xeConfigur ation()
Can you please give me an example?
I would replace
Dim strConnectionString As String
strConnectionString = ConfigurationSettings.AppS ettings("C onnectionS tring")
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
Can you please give me an example?
I would replace
Dim strConnectionString As String
strConnectionString = ConfigurationSettings.AppS
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi Johnnyg have you tried this
ASKER
I am getting a type exepected error in the
Dim config As System.Configuration.Confi guration
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?
Dim config As System.Configuration.Confi
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?
ASKER
Deepesh,
Thanks for your input.
I found a hack work around but wanted to acknowledge your contributions.
Thanks for your input.
I found a hack work around but wanted to acknowledge your contributions.
ASKER
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=custa
<add key="LastUpdated" value="10/12/06"/>
</appSettings>
</configuration>