mcain_bba
asked on
How do I rewrite the following AppSettings vs2003 statement in vs2005?
Hi,
How do I rewrite the following AppSettings vs2003 statement in vs2005?
Dim StrConn As String = ConfigurationSettings.AppS ettings.Ge t("CN1Str" )
Thanks
Mc
How do I rewrite the following AppSettings vs2003 statement in vs2005?
Dim StrConn As String = ConfigurationSettings.AppS
Thanks
Mc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
An easier way to reference the appsettings is:
ConfigurationSettings.AppS ettings("C N1Str")
You don't have to use the Get method because it is an indexed array in the AppSettings. You can reference by index or key name.
ConfigurationSettings.AppS
You don't have to use the Get method because it is an indexed array in the AppSettings. You can reference by index or key name.
ASKER
I have tried all three ways. They each have value, but I must be missing something big, because each gives a different error message. See below. I do not think this makes a differance, but this is a vs2003 app that was coverted to vs2005.
Imports System.Data.OracleClient
Imports System.Configuration
Module ModFldDef
Sub Main()
Dim StrConn As String = ConfigurationManager.AppSe ttings.Get ("CN1Str")
'There is a blue line under ConfigurationManager and saids "ConfigurationManager is not declared"
End Sub
Dim StrConn As String = My.Settings.CN1Str
'There is a blue line under My.Settings and saids "Settings is not a member of My"
ConfigurationSettings.AppS ettings("C N1Str")
'There is a blue line udner ConfigurationSettings and saids "Declaration expected"
End Module
Thanks
Mc
Imports System.Data.OracleClient
Imports System.Configuration
Module ModFldDef
Sub Main()
Dim StrConn As String = ConfigurationManager.AppSe
'There is a blue line under ConfigurationManager and saids "ConfigurationManager is not declared"
End Sub
Dim StrConn As String = My.Settings.CN1Str
'There is a blue line under My.Settings and saids "Settings is not a member of My"
ConfigurationSettings.AppS
'There is a blue line udner ConfigurationSettings and saids "Declaration expected"
End Module
Thanks
Mc
i was the one who posted
Dim StrConn As String = My.Settings.CN1Str
this certainly is the easiest way to access setting in 2005.
the class My.Settings will be auto generated (much like a tableadapter class) whenever you create new settings in your project. i assume you already went to Project Properties/Settings and created the setting "CN1Str" that you intend to use in your app. if not, create it, save and compile, and you should get the My.Settings namespace.
NY
Dim StrConn As String = My.Settings.CN1Str
this certainly is the easiest way to access setting in 2005.
the class My.Settings will be auto generated (much like a tableadapter class) whenever you create new settings in your project. i assume you already went to Project Properties/Settings and created the setting "CN1Str" that you intend to use in your app. if not, create it, save and compile, and you should get the My.Settings namespace.
NY
I thought you would know you have to set this value to a variable, but I guess I should have posted that. so try this:
Dim StrConn As String = System.ConfigurationSettin gs.AppSett ings("CN1S tr")
Dim StrConn As String = System.ConfigurationSettin
ASKER
Newyuppie,
I do not think My.Settings will work because the data is dynamic. The value of the string needs to change without recompiling. I am using App.Config the change the data source to test or production.
<appSettings>
<add key="CN1Str" value="user id=ASNUSER;data source=FIRMTEST;password=x xxxx" />
</appSettings>
strickdd,
ConfigurationSettings.AppS ettings("C N1Str") Works, but is obsolete in 2005
Thanks
Mc
I do not think My.Settings will work because the data is dynamic. The value of the string needs to change without recompiling. I am using App.Config the change the data source to test or production.
<appSettings>
<add key="CN1Str" value="user id=ASNUSER;data source=FIRMTEST;password=x
</appSettings>
strickdd,
ConfigurationSettings.AppS
Thanks
Mc
you can use my code to set and get the setting, unless you have set it to Application Scope in which case it will always be ReadOnly. Set it to UserScope and try it. did you try this or just saying?
The trick to get the code:
Sub Main()
Dim StrConn As String = ConfigurationManager.AppSe ttings.Get ("CN1Str")
'There is a blue line under ConfigurationManager and saids "ConfigurationManager is not declared"
End Sub
to work is to specifically add a reference to system.configuration to your references. You can have an import for system.configuration without it, but it can't resolve the call until it has the DLL reference.
Sub Main()
Dim StrConn As String = ConfigurationManager.AppSe
'There is a blue line under ConfigurationManager and saids "ConfigurationManager is not declared"
End Sub
to work is to specifically add a reference to system.configuration to your references. You can have an import for system.configuration without it, but it can't resolve the call until it has the DLL reference.
I'm sorry, I copied the wrong thing try:
Dim StrConn As String = System.ConfigurationManage r.AppSetti ngs("CN1St r")
Dim StrConn As String = System.ConfigurationManage
Hi mcain_bba ,
You need to get used to using my.settings if your using 2005 as what newyuppie explained earlier.
So using the following line would do the job, providing you have the property setting in the config file.
And you CAN update this in your application or when deployed via the config file.
dim m StrConn As String = My.Settings.CN1Str
You need to get used to using my.settings if your using 2005 as what newyuppie explained earlier.
So using the following line would do the job, providing you have the property setting in the config file.
And you CAN update this in your application or when deployed via the config file.
dim m StrConn As String = My.Settings.CN1Str
I think newyuppie should get the points.
Although all where right (ish), newyuppie's was the precise answer for this question.
Although all where right (ish), newyuppie's was the precise answer for this question.
Add an Imports System.Configuration line
Change the line to: Dim StrConn As String = ConfigurationManager.AppSe
Imports System.Configuration
Module Module1
Sub Main()
Dim StrConn As String = ConfigurationManager.AppSe
End Sub
End Module