ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Microsoft Related  >>  ASP.NET
 
 


 

 
 Visual Basic interview questions  Visual Basic Interview Questions
 C Sharp interview questions  C Sharp Interview Questions
 ASP.NET interview questions  ASP.NET Interview Questions
 VB.NET interview questions  VB.NET Interview Questions
 COM+ interview questions  COM+ Interview Questions
 ADO.NET interview questions  ADO.NET Interview Questions
 IIS interview questions  IIS Interview Questions
 MTS interview questions  MTS Interview Questions
 Crystal Reports interview questions  Crystal Reports Interview Questions
 BizTalk interview questions  BizTalk Interview Questions
 Dot Net interview questions  Dot Net Interview Questions
 Exchange Server interview questions  Exchange Server Interview Questions
 SharePoint interview questions  SharePoint Interview Questions
 Microsoft Related AllOther interview questions  Microsoft Related AllOther Interview Questions
Question
difference between writing connection string in web.config 
through connection string and appsettings
 Question Submitted By :: Swapna
I also faced this Question!!     Rank Answer Posted By  
 
  Re: difference between writing connection string in web.config through connection string and appsettings
Answer
# 1
Introduction

In many cases, we need to use some data string throughout
the application, database connection string is the best
example of it. Instead of writing the connection string
wherever we are creating a connection, its good practice
(and easy to maintain too) to store it into web.config file
and get it at desired place.

Places to store data into Web.Config file

There are two places where we can store data into our
web.config file. These are appSettings and
connectionStrings. Following is the code snippet from the
web.config file where we can store data and retrieve at
later point of time.

<configuration>

<appSettings>

<add key="ConnStr" value="Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\MyData\App_Data\Database.mdf;Integrated
Security=True;User Instance=True"/>

</appSettings>

<connectionStrings>

<add name="ConnStr" connectionString="Data
Source=.\SQLEXPRESS;AttachDbFilename=C:\MyData\App_Data\Database.mdf;Integrated
Security=True;User Instance=True"/>

</connectionStrings>

</configuration>

 

Here appSettings is meant for any data string that can be
stored while connectionString is meant for storing the
database connection strings only.

 
How to Get data from Web.Config

Getting data from web.config file is simple. If you want to
get data from appSettings tag then you need to write
following code

string connStr =
System.Configuration.ConfigurationManager.AppSettings["ConnStr"].ToString();

To get data from web.config file stored under
connectionStrings tag, you need to write following code

string connStr =
System.Configuration.ConfigurationManager.ConnectionStrings["ConnStr"].ToString();

 
Getting connectionStrings value into .aspx page

If for some reason you want to access the string stored in
connectionStrings tag into .aspx page (You may need this
while using SqlDataSource control), you need to write
following code (Notice the code in the pink color <%$
ConnectionStrings:ConnStr %>).

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString='<%$ ConnectionStrings:ConnStr %>'

SelectCommand="Select * FROM SampleForTutorials ORDER BY
[Name]" DataSourceMode="DataSet">

</asp:SqlDataSource>

 
Conclusion

Web.Config file is the best place to store small and simple
string that can be used throught the application. Using
System.Configuration.ConfigurationManager class that exists
in System.Configuration namespace, we can retrive them
wherever we need.
 
Is This Answer Correct ?    13 Yes 1 No
Ramesh P
 
  Re: difference between writing connection string in web.config through connection string and appsettings
Answer
# 2
 both section are used for describing database strings and
values .This is used throughout our project if we using web
applications. 
 
Is This Answer Correct ?    3 Yes 2 No
Bathirasamy
 
 
 

 
 
 
Other ASP.NET Interview Questions
 
  Question Asked @ Answers
 
Whats MSIL, and why should my developers need an appreciation of it if at all?  1
Can you store dataset in viewstate? Microsoft3
In a Code-Behind class generally which type of code is found ?  3
What is CSS? What is the advantage os using CSS in ASP.NET Web Applications? PCS2
In the context of a comparison, what is object identity versus object equivalence?  1
I have around 200+ controls in a page. Each of the sets of controls are kept in divs and when header div is clicked, only those div controls pertaining to that header div will be displayed. Rest of the divs are kept invisible. When the page loads, all these 200+ controls are loaded simultaneously, that consumes much of the time. What my requirement is I want to get the div1 controls loaded when the page loads and rest of the div controls should be loaded asynchronously. it should not be loaded with page load, so that time for loading the page can be much minimised. Hope u understood my question and pls help me out with a solution asap....  1
What is the need of client side and server side validation ? Keane-India-Ltd1
What is the answer for "Which configuration Tool your using means" ? we have to tell about IIS or .Net Framework or VSS? Give me in brief ? eXensys2
What is the difference between an EXE and a DLL?  6
Suppose you display a data having 200 records in a datagrid. Then you edit 100 records of them. Now when you will press update button,all 100 records should be updated in single shot rather than reading every record and updating. How to do it? Wipro2
What?s the difference between Response.Write() andResponse.Output.Write()? Atos-Origin5
What does assemblyinfo.cs file consist of? Accenture1
Which method do you invoke on the DataAdapter control to load your generated dataset with data?  2
What property must you set, and what method must you call in your code, in order to bind the data from some data source to the Repeater control?  3
when the user control event occur in ASp page life cycle?  3
What is the Web.config file used for? a) To store the global information and variable definition for the application. b) Configures the time that the server-side codebehind module is called c) To Configure the Web Server. d) To Configure the Web browser. Syntax-Softtech3
Breifly explain about stack and heap memory Managemet?  1
how to use html code in asp source code?  1
What is boxing? Misys4
# What is the transport protocol you use to call a Web service?  1
 
For more ASP.NET Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com