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 is ado connection?

701


Which provider is used to connect ms access, oracle, etc…?

738


oledbdataadpter with ms access in c#.net giving exception System.Data.OleDb.OleDbException while writing adapter.update(dataset,"tabname"); how to update the database from dataset?

2135


What is difference in record set and dataset?

742


What is the difference between statement and preparedstatement interface?

771


What is ado.net and its features?

731


What is the role of data provider in ado.net?

744


What is ado net stands for?

708


What is ado.net in vb net?

687


What are the steps you will take to improve performance? Will you use dataset or datareader?

744


Which property is used to check whether a DataReader is closed or opened?

803


How many major types of connection objects in ADO.NET?

806


Which method in OLEDBAdapter is used to populate dataset with records?

773


Why is ADO.NET serialization slower than ADO ?

821


What is data access pattern?

675