Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.5 C#
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></connectionstrings>
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 at 24-Jun-11 14:46pm
   
Have a my 5 for nice answer :)
CS1401 at 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 at 24-Jun-11 12:20pm
   
Have a 5 on me for humor!
RaviRanjankr at 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 at 24-Jun-11 14:47pm
   
Nice Answer RK, My 5 :)
Ramalinga Koushik at 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
0 Maciej Los 589
1 OriginalGriff 309
2 CPallini 205
3 RyanDev 165
4 Sergey Alexandrovich Kryukov 110
0 OriginalGriff 5,689
1 Sergey Alexandrovich Kryukov 4,803
2 Peter Leow 2,974
3 Maciej Los 2,819
4 DamithSL 2,465


Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 24 Jun 2011
Copyright © CodeProject, 1999-2014
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