Click here to Skip to main content
12,300,841 members (62,600 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: .NET3.5 C# .NET
Hi

I want to know how the connectionstring is retrieved from this code

Application[Constants.appSettingsDataFolderPath] = ConfigurationManager.AppSettings[Constants.appSettingsDataFolderPath]

Thanks
Akila
Posted 22-Jun-11 1:26am
Edited 22-Jun-11 1:29am
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

if you use .net 2.0 you can only declare connectionstring within in web.config.

but if you use .net 3.5 means you can directly specify connectionstring within tags in webconfig.
---------------------------------------------------------------------------------
in .NET 3.5:

<connectionstrings>
  <add>
    name="ConnectionStringname";
    connectionString="Data Source=serverName;Initial
    Catalog=yourdb;Persist Security Info=True;User
    ID=userName;Password=password";>
 
</add>
you can call it in program by using,
string connStr = ConfigurationManager.ConnectionStrings["ConnectionStringname"].ConnectionString;
-----------------------------------------------------------------------------------
in .NET 2.0:

<appsettings>
    <add key="ConnectionInfo" value="server=(local);database=yourdb;Integrated Security=SSPI">
  </add></appsettings>
you can call it in program by using,
string connectionInfo = ConfigurationSettings.AppSettings["ConnectionInfo"];
  Permalink  
Comments
RaviRanjankr 24-Jun-11 14:46pm
   
Have a my 5 for nice answer :)
CS1401 24-Jun-11 23:57pm
   
Thankx...

.!.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Put a debug point here trace using F10 put the value in quick watch window
  Permalink  
Comments
Manfred R. Bihy 24-Jun-11 12:20pm
   
Have a 5 on me for humor!
RaviRanjankr 24-Jun-11 14:46pm
   
My 5 too :)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

      The Connection String which you wrote in the Web.config or app.config in the Appsettings section is retrieved using Configuration Manager Class.

Thanks,
K.Vigneshwar.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

If you need help on the AppSettings property - see here[^].
This property returns an AppSettingsSection object contains the contents of the configuration file's appSettings section.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Use Configuration Manager class to retrieve the connection string which you wrote in app (or)web.config.
  Permalink  
Comments
RaviRanjankr 24-Jun-11 14:47pm
   
Nice Answer RK, My 5 :)
Ramalinga Koushik 27-Jun-11 0:11am
   
Thanks Ravi.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160525.2 | Last Updated 24 Jun 2011
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100