Problems accessing configuration file in .NET 2.0

S

Stacey

I am using Visual Studio 2005, creating a VB.NET program. I am have created
a settings file and two settings in the file. The section that it created
in my app.config is below. I can not figure out how to access the two
settings. I need to be able to get the data out of the settings. And update
them at a later point as well. I have tried all sorts of things.
Dim CurReceipt As Integer =
CInt(ConfigurationManager.AppSettings("ReceiptNumber"))

Dim CurTrans As Int64 =
CLng(ConfigurationManager.AppSettings("TransactionNUmber"))

Each of the above lines just return 0. According to the help file, i
should be able to use My.Settings.ReceiptNumber - but that is not
available. Any ideas? Thanks
Stacey

<applicationSettings>

<GiftGards.Cards>

<setting name="ReceiptNumber" serializeAs="String">

<value>50</value>

</setting>

<setting name="TransactionNumber" serializeAs="String">

<value>1000</value>

</setting>

</GiftGards.Cards>

</applicationSettings>

-----------WARNINGS AND ERROR MESSAGES BELOW-------------
Warning 1 The 'requirePermission' attribute is not declared. D:\Projects
..NET\RTCGiftGards\RTCGiftGards\app.config 5 176 RTCGiftGards
Message 2 Could not find schema information for the element
'applicationSettings'. D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config
30 6 RTCGiftGards
Message 3 Could not find schema information for the element
'RTCGiftGards.RTCCards'. D:\Projects
..NET\RTCGiftGards\RTCGiftGards\app.config 31 10 RTCGiftGards
Message 4 Could not find schema information for the element 'setting'.
D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 32 14 RTCGiftGards
Message 5 Could not find schema information for the attribute 'name'.
D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 32 22 RTCGiftGards
Message 6 Could not find schema information for the attribute 'serializeAs'.
D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 32 43 RTCGiftGards
Message 7 Could not find schema information for the element 'value'.
D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 33 18 RTCGiftGards
Message 8 Could not find schema information for the element 'setting'.
D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 35 14 RTCGiftGards
Message 9 Could not find schema information for the attribute 'name'.
D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 35 22 RTCGiftGards
Message 10 Could not find schema information for the attribute
'serializeAs'. D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 35 47
RTCGiftGards
Message 11 Could not find schema information for the element 'value'.
D:\Projects .NET\RTCGiftGards\RTCGiftGards\app.config 36 18 RTCGiftGards
 
S

Stacey

Unless I am missing things, I am doing it that way. I told it to create a
new settings file. and it does.. but it also writes the entires into the
app.config. The file it creates is called RTCCards.settings and it has my
two values in it.
 
J

Jeffrey Tan[MSFT]

Hi StaceyL,

Thanks for your post.

Can you show us how you added the settings in app.config? Do you use the
Settings.settings designer?

Normally, after we adding the setting in the designer, we should can refer
the item with My.Settings.[item name] in VB.net code file.

If you failed to do this, can you provide some detailed steps to reproduce
your problem?

Below is the official document for manipulating the application settings in
VS2005:
"Accessing Application Settings "
http://msdn2.microsoft.com/en-us/library/bc6ws923.aspx
"Managing Application Settings"
http://msdn2.microsoft.com/en-us/library/c9db58th.aspx

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
S

Stacey

I added the strings using the designer. Ie.. right click on the solution.
Add --> New --> Settings file. Enter my two settings into the settings file.
They are not accessible.
 
J

Jeffrey Tan[MSFT]

Hi Stacey,

Thanks for your feedback.

No, we should not add a new Settings.settings file. We should use the
default Settings.settings file to store the application/user config data.
Then VB.net20005 designer will associate them in My.Settings class.

To use the default Settings.settings file, we can right click Project node
in the solution explorer, then choose the "Properties" to open the "Project
Properties" tab. Then we can click "Settings" tab in the "Project
Properties" tab. At last, we can set the config data in the designer.

After this, we should can use it in the code file.

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top