Sie sind auf Seite 1von 3

Basic ADO.

NET Interview Questions


What is Microsoft ADO.NET?
Visual Stuio .NET !rovies access to ata"ases throu#h the set of tools an na$es!aces collectivel% referre to as
Microsoft ADO.NET
What are the & $a'or t%!es of connection o"'ects in ADO.NET?
OleD"(onnection o"'ect ) *se an OleD"(onnection o"'ect to connect to a Microsoft Access or thir+!art% ata"ase,
such as M%SQ-. O-E ata"ase connections use the OleD"DataAa!ter o"'ect to !erfor$ co$$ans an return
ata.
S.l(onnection o"'ect ) *se a S.l(onnection o"'ect to connect to a Microsoft SQ- Server ata"ase. SQ- ata"ase
connections use the S.lDataAa!ter o"'ect to !erfor$ co$$ans an return ata.
Oracle(onnection o"'ect ) *se an Oracle(onnection o"'ect to connect to Oracle ata"ases. Oracle ata"ase
connections use the OracleDataAa!ter o"'ect to !erfor$ co$$ans an return ata. This connection o"'ect was
introuce in Microsoft .NET /ra$ewor0 version 1.1.
-ist the 2 co$$on ADO.NET Na$es!aces?
S%ste$.Data ) (ontains (lasses, t%!es, an services for creatin# an accessin# ata sets an their su"orinate
o"'ects
S%ste$.Data.S.l(lient ) (ontains (lasses an t%!es for accessin# Microsoft SQ- Server ata"ases
S%ste$.Data.Oracle(lient ) (ontains (lasses an t%!es for accessin# Oracle ata"ases 3Microsoft .NET /ra$ewor0
version 1.1 an later4
S%ste$.Data.OleD" ) (ontains (lasses an t%!es for accessin# other ata"ases
-ist all the ste!s in orer, to access a ata"ase throu#h ADO.NET?
1. (reate a connection to the ata"ase usin# a connection o"'ect.
5. Invo0e a co$$an to create a DataSet o"'ect usin# an aa!ter o"'ect.
&. *se the DataSet o"'ect in coe to is!la% ata or to chan#e ite$s in the ata"ase.
2. Invo0e a co$$an to u!ate the ata"ase fro$ the DataSet o"'ect usin# an aa!ter o"'ect.
6. (lose the ata"ase connection if %ou e7!licitl% o!ene it in ste! 5 usin# the O!en $etho. Invo0in# co$$ans
without first invo0in# the O!en $etho i$!licitl% o!ens an closes the connection with each re.uest.
Wh% will %ou usuall% create an AS8NET user account in the Data"ase for an AS8.NET we" a!!lication?
We" a!!lications run usin# the AS8NET user account. The SQ- ata"ase a$inistrator will have to set u! this
account an #rant it !er$issions "efore %our We" a!!lication will have access to a SQ- ata"ase. /or file+"ase
ata"ases, such as Microsoft Access, %ou $ust #rant !er$issions on the ata"ase file to the AS8NET user account
usin# Winows file securit% settin#s.
What is the ifference "etween Data9eaer an DataAa!ter?
1. Data 9eaer is rea onl% forwar onl% an $uch faster than DataAa!ter.
5. If %ou use Data9eaer %ou have to o!en an close connection e7!licitl% where as if %ou use DataAa!ter the
connection is auto$aticall% o!ene an close.
&. Data9eaer is connection oriente where as Data Aa!ter is isconnecte
(an %ou inherit fro$ S.l(onnection (lass?
No, %ou cannot inheirt fro$ S.l(onnection (lass. S.l(onnection (lass is a seale class. It is a co$!ile ti$e error.
Will the connection "e close, if the S.l(onnection o"'ect #oes out of sco!e?
No, If the S.l(onnection #oes out of sco!e, it won:t "e close. Therefore, %ou $ust e7!licitl% close the connection
"% callin# (lose or Dis!ose.
What ha!!ens if connection !oolin# is ena"le?
If connection !oolin# is ena"le an when %ou call (lose or Dis!ose $ethos, then the connection is returne to the
connection !ool. This connection can then "e resuse.If connection !oolin# is isa"le an when %ou call (lose or
Dis!ose $ethos, the unerl%in# connection to the server is actuall% close.
;ow o %ou ensure that the ata"ase connections are alwa%s close?
To ensure that the ata"ase connections are alwa%s close, o!en the connection insie of a usin# "loc0, as shown in
the followin# coe fra#$ent. Doin# so ensures that the connection is auto$aticall% close when the coe e7its the
"loc0.
usin# 3S.l(onnection (onnectionO"'ect < new S.l(onnection344
=
(onnectionO"'ect.O!en34>
??The ata"ase connection will "e close when the control e7its the usin# coe "loc0
@
;ow o %ou rea an AM- file into a DataSet?
*sin# the DataSet o"'ectBs 9eaAM- $etho.
When o %ou use E7ecute9eaer, E7ecuteNonQuer%, E7ecuteScalar $ethos?
If the co$$an or store !roceure that is "ein# e7ecute returns a set of rows, then we use E7ecute9eaer $etho.
If the co$$an or store !roceure that is "ein# e7ecute returns a sin#le value then we use E7ecuteScalar $etho.
If the co$$an or store !roceure !erfor$s INSE9T, DE-ETE or *8DATE o!erations, then we use
E7ecuteNonQuer% $etho. E7ecuteNonQuer% $etho returns an inte#er s!ecif%in# the nu$"er of rows inserte,
elete or u!ate.
(an %our class inherit fro$ S.l(o$$an (lass?
No, %ou cannot inheirt fro$ S.l(o$$an (lass. S.l(o$$an (lass is a seale class. It is a co$!ile ti$e error.
Cive an e7a$!le that shows how to e7ecute a store !roceure in ADO.NET?
usin# 3S.l(onnection (onnectionO"'ect < new S.l(onnection344
=
??S!ecif% the na$e of the store !roceure to e7ecute an the (onnection O"'ect to use
S.l(o$$an (o$$anO"'ect < new S.l(o$$an3DStore8roceureNa$eD, (onnectionO"'ect4>
??S!ecif% the SQ- (o$$an t%!e is a store !roceure
(o$$anO"'ect.(o$$anT%!e < (o$$anT%!e.Store8roceure>
??O!en the connection
(onnectionO"'ect.O!en34>
??E7ecute the Store 8roceure
int 9ecorsAffecte < (o$$anO"'ect.E7ecuteNonQuer%34>
@
(an %ou reuse a S.l(o$$an o"'ect?
Ees, %ou can reset the (o$$anTe7t !ro!ert% an reuse the S.l(o$$an o"'ect.
What are the $ethos that can ensure as%nchronous e7ecution of the Transact+SQ- state$ent or store !roceure?
Be#inE7ecuteNonQuer%
Be#inE7ecute9eaer
What is S.l(o$$an.(o$$anTi$eout 8ro!ert% use for?
(o$$anTi$eout 8ro!ert% is use to Cet or set the wait ti$e "efore ter$inatin# the atte$!t to e7ecute a co$$an
an #eneratin# an error.
??S!ecif% the (o$$anTi$eout !ro!ert% value
S.l(o$$an (o$$anO"'ect < new S.l(o$$an3DStore8roceureNa$eD, (onnectionO"'ect4>
??Wait for 1F secons to e7ecute the Store !roceure
(o$$anO"'ect.(o$$anTi$eout < 1F>
The ti$e is in secons. The efault is &F secons

Das könnte Ihnen auch gefallen