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

Why is ADO.NET serialization slower than ADO ?

835


What are the benefits of using of ADO.NET in .NET 4.0?

755


How can we add relation between tables in a dataset?

769


What is the role of the dataset object in ado.net?

816


What are the pre-requisites for connection pooling?

750


Which namespaces are used for data access?

875


Can we load multiple tables in a dataset?

822


What are the uses of Stored Procedure?

794


What is the provider being used to access oracle database?

759


What is the difference between Data adaptor and Data set?

810


What is oledb connection?

730


How do you connect to sql server database without using sqlclient?

795


Explian About DataAdapters

805


What we do with the object of ado.net dataset after using it?

735


Is it possible to edit data in Repeater control?

718