Unable to access connection string from app config
-
I have been trying for hours now. but unable to access the connection strng from app config file. 1. Application has reference to System.Configuration.dll 2. App Config file has the connectionString still the following code returns nothing.
Private Shared Function GetConnectionString( _
ByVal name As String) As StringDim returnValue As String = Nothing Dim settings As ConnectionStringSettings = \_ ConfigurationManager.ConnectionStrings(name) If Not settings Is Nothing Then returnValue = settings.ConnectionString End If Return returnValue
End Function
can any one guess what's going wrong?
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
-
I have been trying for hours now. but unable to access the connection strng from app config file. 1. Application has reference to System.Configuration.dll 2. App Config file has the connectionString still the following code returns nothing.
Private Shared Function GetConnectionString( _
ByVal name As String) As StringDim returnValue As String = Nothing Dim settings As ConnectionStringSettings = \_ ConfigurationManager.ConnectionStrings(name) If Not settings Is Nothing Then returnValue = settings.ConnectionString End If Return returnValue
End Function
can any one guess what's going wrong?
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
Hi, just a wild guess, but I think you have to use the connectionstring within the web.config file. ASP.NET projects get their application settings from there. Must look like this:
<connectionStrings>
<add name="MyConnectionString" connectionString="here it goes" />
</connectionStrings>Regards Sebastian
-
Hi, just a wild guess, but I think you have to use the connectionstring within the web.config file. ASP.NET projects get their application settings from there. Must look like this:
<connectionStrings>
<add name="MyConnectionString" connectionString="here it goes" />
</connectionStrings>Regards Sebastian
it's a seperate library project for DataAccess (DAL). Added a app config file. I'm trying to take the connection string from there instead of passing it through the presentation, BAL... this is what I have in app config file
<connectionStrings>
<add name="Name" providerName="Provider Name" connectionString="Connection String" />
</connectionStrings>- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
-
it's a seperate library project for DataAccess (DAL). Added a app config file. I'm trying to take the connection string from there instead of passing it through the presentation, BAL... this is what I have in app config file
<connectionStrings>
<add name="Name" providerName="Provider Name" connectionString="Connection String" />
</connectionStrings>- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
-
I have been trying for hours now. but unable to access the connection strng from app config file. 1. Application has reference to System.Configuration.dll 2. App Config file has the connectionString still the following code returns nothing.
Private Shared Function GetConnectionString( _
ByVal name As String) As StringDim returnValue As String = Nothing Dim settings As ConnectionStringSettings = \_ ConfigurationManager.ConnectionStrings(name) If Not settings Is Nothing Then returnValue = settings.ConnectionString End If Return returnValue
End Function
can any one guess what's going wrong?
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
Have you stepped into the code? Are you getting
ConfigurationManager.ConnectionStrings
asNOTHING
?Navaneeth How to use google | Ask smart questions
-
Have you stepped into the code? Are you getting
ConfigurationManager.ConnectionStrings
asNOTHING
?Navaneeth How to use google | Ask smart questions
-
yes,
ConfigurationManager.ConnectionStrings
returnsNOTHING
. but i have a valid connection string with a NAME and PROVIDER NAME in the app config file.- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
Hi, Try using the following
System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString()
and in app.config
<appSettings>
<add key="ConnectionString" value="Data Source=MyData;Initial Catalog=Data;Integrated Security=False;User id=abcd;Password=1234;"/>
</appSettings> -
Hi, Try using the following
System.Configuration.ConfigurationSettings.AppSettings("ConnectionString").ToString()
and in app.config
<appSettings>
<add key="ConnectionString" value="Data Source=MyData;Initial Catalog=Data;Integrated Security=False;User id=abcd;Password=1234;"/>
</appSettings> -
ConfigurationSettings.AppSettings("DBConnectString")
returnsNOTHING
- Regards -
J O N
A good thing is a bad thing if it keeps you from the best thing. - Dr. Adrian Rogers
Paste the code of your app.config and the code which you are calling to access it