How to you declare connection strings and how to you make
use of web.config ?

Answer Posted / d0tnetf0x

In web.config,we have to give connection to database by add
key which is given in application setting tags.as

<appsettings>
<add key="constr" value="Data Source=SQL-PC;Initial
Catalog=sampledb;User ID=sa;password=password "/>

</appsettings>

//under value we have given the database which is connected.
here under ----data source=servername
intial catalog=database name
user id=username of the database(if give)
password= password(optional)

to use this connection we use configsetting or we caneven
directly give it in sqlconnection

sqlconnection conn=new sqlconnection
(configurationsetting.appsettings("constr"))
here constr is the key we added in application settings to
identify it in web.config
[this connection we used by declearing in web.config]

with out declearation:-
sqlconnection conn=new sqlconnection("Data Source=SQL-
PC;Initial Catalog=sampledb;User ID=sa;password=password ")

better process is useing connection by declearing in
web.config

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the advantages of ado.net?

509


What is the difference between Datareader and Dataset?

541


What are two types of transaction supported by ado.net?

535


What is the use of sqldatareader class?

477


What are different layers of ADO.Net?

590






What is linq and entity framework?

517


What does adodb stand for?

508


What is the difference between a datareader and a dataset?

518


How to identify the controls which can be used for binding data?

551


What are the data providers used in ado.net

544


What are the data providers in ADO.NET framework?

594


Define data adapter?

513


Explain why canot we use multiple inheritance and garbage collector paralelly in .net?

595


What do you know about ado.net's methods?

589


Can we connect two dataadapters to same data source using single connection at same time?

531