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

How to copy the contents from one table to another table and how to delete the source table in ado.net?

617


What is ole access?

615


How does entity framework work?

556


Does dapper use ado.net?

674


What is command class in ado.net?

560






What is sqldatareader in ado.net?

576


Name which operations can you not perform on an ado.net dataset?

569


Explain what are the steps to connect to a database?

592


What are two important objects of ADO.Net?

647


What does executequery return?

597


What is connection pooling and what is the maximum pool size in ado.net connection string?

599


What are the advantage of ado.net?

611


Explain executenonquery?

661


How does ado.net work?

574


What is the difference between an ADO.NET Dataset and an ADO Recordset?

644