Beruflich Dokumente
Kultur Dokumente
NET
Sunday, January 15, 2012 What is the difference between Execute Reader, Execute Scalar and Execute Non Query methods?
Execute Reader Execute Reader will be used to return the set of rows, on execution of SQL Query or Stored procedure using command object. Execute Scalar Execute Scalar will be used to return the single value, on execution of SQL Query or Stored procedure using command object. Execute Non Query If the command or stored procedure performs INSERT, DELETE or UPDATE operations, then we use Execute Non Query method. Execute Non Query method returns an integer specifying the number of rows inserted, deleted or updated.
What are advantages and disadvantages of Microsoft-provided data provider classes in ADO.NET?
SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLEDB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix, but it's a .NET layer on top of OLE layer, so not the fastest thing in the world. ODBC.NET is a deprecated layer provided for backward compatibility to ODBC engines.
Named out assemblies and corresponding namespace of all .Net framework data provider.
a) .Net Framework Data Provider for SQL Server Assembly Name :- System.Data.dll NameSpace :- System.Data.SqlClient b) .Net Framework Data Provider for OLE DB Server Assembly Name :- System.Data.dll NameSpace :- System.Data.OleDb
C) .Net Framework Data Provider for Oracle Assembly Name :- System.Data.OracleClient.dll NameSpace :- System.Data.OracleClient
List out Some feature of ADO.net The Key feature of ADO.Net are
a) Disconnected Data Architecture b) Data cached in datasets c) Scalability d) Data transfer in XML format.
OleDbConnection cnn ; connetionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=DatabaseName;"; cnn = new OleDbConnection(connetionString); . SqlConnection object used the Tabular Data Services (TDS) With MS Sql Server.
SqlConnection con; con = new SqlConnection("server=SERVER NAME;user id=ID;password=PASSWORD;database=DB NAME"); SqlCommand cmd; cmd = new SqlCommand("DB Query Here",con); . Using the OdbcConnection , we will create an OdbcCommand. From that command we can issue a Query and create an OdbcDataReader.
OdbcConnection DbConnection = new OdbcConnection("Connection String"); OdbcCommand DbCommand = DbConnection.CreateCommand(); DbCommand.CommandText = "Db Query Here"; OdbcDataReader DbReader = DbCommand.ExecuteReader();
1>Scalability:ADO.NET works on DataSet that can represent a whole database or even a data table as a disconnected object and thereby eliminates the problem of the constraints of number of databases being connected. In this way scalability is achieved. 2>Data Source Independence:In ADO.NET DataSet is completely independent of data source and no way DataSet is controlled by the data source as it happens
in case of RecordSet. 3>Interoperability:As ADO.NET transmits the data using the format of XML which is not dependent on ADO.NET or windows platform. 4>Strongly Typed Fields:It supports strongly typed fields by using CTS. 5>Performance:The performance in ADO.NET is higher in comparison to ADO that uses COM marshalling. 6>Firewall: As in ADO.NET transmission is via XML format, therefore it can pass through firewalls.
ado VS ado.Net
*)ado is connected mode always where as ado.net is connected as well as disconnected. *)ado ---recordset whereas ado.net ---dataset *)ado---c,c++whereas ado.net---- .net framework *)ado--server based whereas ado.net --client
What is Dataset?
A DataSet is Disconnected Architecture,means their is no need to always open & close connection. It is cache of data retrieved from database. It is made up of collection of datatable. Dataset can be Typed & UnTyped usually, datasets are typed in Visual basic.A typed dataset is dataset which derived from dataset class & uses information in XML schema file(XSD file).An untyped dataset has no built in schema.it can contain tables,column & rows.but those are exposed only as collections
The default timeOut is 30 seconds. If you want to increase the TimeOut see the below example code For example:SqlCommand cmd = new SqlCommand("select * from tablename", conn); cmd.CommandTimeout = 50; SqlDataReader dr = cmd.ExecuteReader();
What is a DataSet?
The Dataset is the central object in ADO.NET. DataSet is a nogical container of data. It represents a set of data tables referenced as one unit in the application. With this object you can get all the data you need from each table quickly, examine and change it while you are disconnected from the server and then update the server with changes in an efficient operation.
BENEFITS OF ADO.NET -------------------1>Scalability:ADO.NET works on DataSet that can represent a whole database or even a data table as a disconnected object and thereby eliminates the problem of the constraints of number of databases being connected. In this way scalability is achieved. 2>Data Source Independence:In ADO.NET DataSet is completely independent of data source and no way DataSet is controlled by the data source as it happens in case of RecordSet. 3>Interoperability:As ADO.NET transmits the data using the format of XML which is not dependent on ADO.NET or windows platform. 4>Strongly Typed Fields:It supports strongly typed fields by using CTS. 5>Performance:The performance in ADO.NET is higher in comparison to ADO that uses COM marshalling. 6>Firewall: As in ADO.NET transmission is via XML format, therefore it can pass through firewalls.
Which method do you invoke on the DataAdapter control to load your generated dataset with data?
System.Data.Common.DataAdapter.Fill(System.Data.DataSet);
Can you explain the difference between an ADO.NET Dataset and an ADO Recordset?
In ADO, the in-memory representation of data is the recordset. In ADO.NET, it is the dataset. There are important differences between them. o A recordset looks like a single table. If a recordset is to contain data from multiple database tables, it must use a JOIN query, which assembles the data from the various database tables into a single result table. In contrast, a dataset is a collection of one or more tables. The tables within a dataset are called data tables; specifically, they are DataTable objects. If a dataset contains data from multiple database tables, it will typically contain multiple DataTable objects. That is, each DataTable object typically corresponds to a single database table or view. In this way, a dataset can mimic the structure of the underlying database. A dataset usually also contains relationships. A relationship within a dataset is analogous to a foreign-key relationship in a database -that is, it associates rows of the tables with each other. For example, if a dataset contains a table about investors and another table about each investor's stock purchases, it could also contain a relationship connecting each row of the investor table with the corresponding rows of the purchase table. Because the dataset can hold multiple, separate tables and maintain information about relationships between them, it can hold much richer data structures than a recordset, including self-relating tables and tables with many-to-many relationships. o In ADO you scan sequentially through the rows of the recordset using the ADO MoveNext method. In ADO.NET, rows are represented as collections, so you can loop through a table as you would through any collection, or access particular rows via ordinal or primary key index. DataRelation objects maintain information about master and detail records and provide a method that allows you to get records related to the one you are working with. For example, starting from the row of the Investor table for "Nate Sun," you can navigate to the set of rows of the Purchase table describing his purchases. A cursor is a database element that controls record navigation, the ability to update data, and the visibility of changes made to the database by other users. ADO.NET does not have an inherent cursor object, but instead includes data classes that provide the functionality of a traditional cursor. For example, the functionality of a forward-only, read-only cursor is available in the ADO.NET DataReader object. For more information about cursor functionality, see Data Access Technologies. o Minimized Open Connections: In ADO.NET you open connections only long enough to perform a database operation, such as a Select or Update. You can read rows into a dataset and then work with them without staying connected to the data source. In ADO the recordset can provide disconnected access, but ADO is designed primarily for connected access. There is one significant difference between disconnected processing in ADO and ADO.NET. In ADO you communicate with the database by making calls to an OLE DB provider. In ADO.NET you communicate with the database through a data adapter (an OleDbDataAdapter, SqlDataAdapter, OdbcDataAdapter, or OracleDataAdapter object), which makes calls to an OLE DB provider or the APIs provided by the underlying data source. The important difference is that in ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database - by optimizing for performance, performing data validation checks, or adding any other extra processing. Data adapters, data connections, data commands, and data readers
are the components that make up a .NET Framework data provider. Microsoft and third-party providers can make available other .NET Framework data providers that can be integrated into Visual Studio. o Sharing Data Between Applications. Transmitting an ADO.NET dataset between applications is much easier than transmitting an ADO disconnected recordset. To transmit an ADO disconnected recordset from one component to another, you use COM marshalling. To transmit data in ADO.NET, you use a dataset, which can transmit an XML stream. o Richer data types.COM marshalling provides a limited set of data types - those defined by the COM standard. Because the transmission of datasets in ADO.NET is based on an XML format, there is no restriction on data types. Thus, the components sharing the dataset can use whatever rich set of data types they would ordinarily use. o Performance. Transmitting a large ADO recordset or a large ADO.NET dataset can consume network resources; as the amount of data grows, the stress placed on the network also rises. Both ADO and ADO.NET let you minimize which data is transmitted. But ADO.NET offers another performance advantage, in that ADO.NET does not require data-type conversions. ADO, which requires COM marshalling to transmit records sets among components, does require that ADO data types be converted to COM data types. o Penetrating Firewalls.A firewall can interfere with two components trying to transmit disconnected ADO recordsets. Remember, firewalls are typically configured to allow HTML text to pass, but to prevent system-level requests (such as COM marshalling) from passing.
Which is the default Provider Name of the Providers used to access the DataBase?
System.Data.SqlClient
Use this property to specify that a particular connection should not participate in the pool, but instead should be destroyed when it is closed.
Between Windows Authentication and SQL Server Authentication, which one is trusted and which one is untrusted?
Windows Authentication is trusted because the username and password are checked with the Active Directory, the SQL Server authentication is untrusted, since SQL Server is the only verifier participating in the transaction.
To perform asynchronous data access, what must be added to the connection string?
Select Correct Answer. 1. BeginExecute=true 2. MultiThreaded=true 3. MultipleActiveResultSets=true 4. Asynchronous=true Correct Answer: 4. Asynchronous=true
You are working with a DataSet and want to be able to display data, sorted different ways. How do you do so?
Select the correct answer. 1. Use the Sort method on the DataTable object. 2. Use the DataSet object's Sort method. 3. Use a DataView object for each sort. 4. Create a DataTable for each sort, using the DataTable object's Copy method, and then Sort the result
How can we check that some changes have been made to dataset since it was loaded?
The changes made to the dataset can be tracked using the GetChanges and HasChanges methods. GetChanges(): ------------The GetChanges returns dataset which are changed since it was loaded or since Acceptchanges was executed. HasChanges(): -----------The HasChanges property indicates if any changes were made to the dataset since it was loaded or if acceptchanges method was executed. RejectChanges(): ---------------The RejectChanges can be used to revert thee changes made to the dataset since it was loaded
Thread's execution can be caused by calling the Thread.Sleep method. This method takes an integer value that determines how long the thread should sleep. Example Thread.CurrentThread.Sleep(2000).
10
"Thread.CurrentThread" refers to the current thread running in the method."CurrentThread" is a public static property.
The AddressOf operator creates a delegate object to the BackgroundProcess method. A delegate within VB.NET is a type-safe, object-oriented function pointer. After the thread has been instantiated, you begin the execution of the code by calling the Start() method of the thread.
How can we change priority and what the levels of priority are provided by .NET ?
Thread Priority can be changed by using Threadname.Priority = ThreadPriority.Highest. In the sample provided look out for code where the second thread is ran with a high priority. Following are different levels of Priority provided by .NET :. ThreadPriority.Highest . ThreadPriority.AboveNormal . ThreadPriority.Normal . ThreadPriority.BelowNormal . ThreadPriority.Lowest
What is COM ?
Microsoft's COM is a technology for component software development. It is a binary standard which is language independent. DCOM is a distributed extension of COM.
11
ado.net
Description To introduce ADO.NET and to describe how to make connections to databases and run stored procedures and SQL statements in a connected design 1. Which of the following statements about stored procedures are true? Choose more than one option. 1. They reside on the client 2. They reside on the server True 3. You can encapsulate multiple SQL statements in a stored procedure True 4. You encapsulate a single SQL statement in each stored procedure Topic title: Architecture of ADO.NET 2. Which of the following fully qualified names describes the data adapter for a SQL 2000 server? Choose an option. System.Data.SqlClient.DataAdapter System.Data.SqlClient.SqlDataAdapter True System.Data.SqlDataAdapter System.Xml.SqlDataAdapter Topic title: Working with ADO.NET connections in VB.NET 3. Assuming that ReadNextOrder expects one parameter, which options accurately describe this code? Dim cnnOrders As SqlConnection Dim cmd As SqlCommand, drOrders As SqlDataReader cmd = New SqlCommand ("ReadNextOrder", cnnOrders) drOrders = cmd.ExecuteReader () Choose more than one option. The connection must be opened explicitly True The CommandType property must be set to StoredProcedure True The ExecuteNonQuery method should be used for all stored procedures The ExecuteReader method call will fail because no parameter has been added to the Parameters collection True Topic title: Distributed data-access requirements 4. Which of the following attributes in a ConnectionString specifies the SQL Server server used when a connection is open? Choose an option. Initial Catalog Provider Data Source True ConnectionTimeout Topic title: Distributed data-access requirements 5. Connected data-access applications are generally ___________ more than disconnected data-access applications. Choose an option below to fill in the blank. complicated distributed scalable
12
secure True suited to the Internet Topic title: Pooling ADO.NET connections in VB.NET 6. Which of the following statements about the DataReader object are true? Choose more than one option. The DataReader points to the first row of the result set after Read is first called True You create a new DataReader using one of several overloaded constructors You use the ExecuteScalar method of the Command object to obtain a DataReader You use the NextResult method on the DataReader to get the next result set True Topic title: Pooling ADO.NET connections in VB.NET 7. Which of the following methods of a DataReader enable you to obtain column metadata? Choose more than one option. GetString GetName True GetOrdinal True GetSchemaTable True GetDateTime Topic title: Defining an ADO.NET Connection object in VB.NET 8. Which of the following are implementations of Command classes for .NET data providers? Choose more than one option. OdbcCommand objects True OleDbCommand objects True SqlCommand objects True XMLCommand objects Topic title: Defining an ADO.NET Connection object in VB.NET 9. Which of the following SqlConnection.ConnectionString attributes determines the number a seconds a connection can stay in a pool? Choose an option. Connection Duration Connection Lifetime True Connection TimeOut Connection Reset Topic title: Pooling ADO.NET connections in VB.NET 10. To specify the name of a stored procedure in .NET code, you use a _____________ object. Choose an option below to fill in the blank. DataSet SqlCommand True SqlConnection SqlDataAdapter
13
Topic title: Architecture of ADO.NET Which of the following objects exclusively contains metadata about tables? Choose an option. The DataColumn object True The DataRow object The DataView object The SqlDataAdapter object Topic title: Distributed data-access requirements 11. Which of these namespaces do you need to reference to connect to a SQL database using the .NET provider for OLEDB? Choose more than one option. System.Data True System.Data.Connect System.Data.Oledb True System.Data.SqlClient Topic title: Architecture of ADO.NET 13. What happens when you try to make the following assignment to an OleDbConnection.ConnectionString property and then try to open that connection? cnNew.ConnectionString = "Data Source=8044DYSZ033R\SQLLOCAL; Initial" & _ "Catalog=Northwind; User ID=sa;" cnNew.Open() Choose an option. It fails to compile It compiles and runs correctly It compiles but throws an ArgumentException because no Provider is included True It compiles but throws an OleDbException when you attempt to open it Topic title: Architecture of ADO.NET 14. What happens when you try to make the following assignment to an OleDbConnection.ConnectionString property and then try to open that connection? cnNew.ConnectionString = "Data Source=8044DYSZ033R\SQLLOCAL; Initial" & _ "Catalog=Northwind; User ID=sa;" cnNew.Open() Choose an option. It fails to compile It compiles and runs correctly It compiles but throws an ArgumentException because no Provider is included True It compiles but throws an OleDbException when you attempt to open it Topic title: Working with ADO.NET connections in VB.NET 15. Which combination of classes do you use when passing arguments to a stored procedure through the SQL .NET Data Provider? Choose an option. Argument and SqlCommand
14
Parameter and SqlCommand SqlArgument and SqlCommand SqlParameter and SqlCommand True Topic title: Working with ADO.NET connections in VB.NET 16. A Command object's property indicates whether an object encapsulates a stored procedure or a SQL statement, or is requesting a full table. Choose an option below to fill in the blank. Connection CommandType True CommandText Parameters Topic title: Architecture of ADO.NET Which method releases unmanaged resources when a connection is closed? Choose an option. Delete Dispose True Open Topic title: Working with ADO.NET connections in VB.NET 17. You use Visual Studio .NET's ___________ to create sequences of SQL commands. Choose an option below to fill in the blank. Toolbox Query Analyzer tool True Properties window Topic title: Distributed data-access requirements 18. Which of the following attributes in a ConnectionString sets the name of the OLE DB or SQL database? Choose an option. Initial Catalog True Provider Data Source ConnectionTimeout Topic title: Architecture of ADO.NET 19. If a connection has a nonfatal error, the ____________ event is thrown. Incorrect. The correct option is as follows InfoMessage True OleDbException SqlException StateChange Topic title: Distributed data-access requirements 20. _______________ eliminates the need for database locks and protracted database connections and facilitates data exchange between tiers. Choose an option below to fill in the blank. A 2-tier application architecture The use of in-memory data caches True The use of strongly typed data
15
XML messaging Topic title: Defining an ADO.NET Connection object in VB.NET 21. If both the ________________ of a client's Connection object match those of a dormant connection in a pool, the client can obtain a connection in that pool. Choose an option below to fill in the blank. connection context and database context connection context and security context security context and pooling context security context and transaction context True Topic title: Defining an ADO.NET Connection object in VB.NET 22. Which of the following SqlConnection.ConnectionString attributes specifies the number of connections that are automatically allocated to a new pool when it's created by a unique connection? Choose an option. Init Pool Size Max Pool Size Min Pool Size True Start Pool Size Topic title: Working with ADO.NET connections in VB.NET 23. When you are stepping through a stored procedure, which of the following types of information are displayed in the Autos window? Choose more than one option. Debug information The contents of the call stack The types of the procedure's variables True The values of the procedure's variables True Topic title: Defining an ADO.NET Connection object in VB.NET 24. Which of the following elements is always incorporated in a Command object? Incorrect. The correct option is as follows
A Connection object True A database table name A set of parameters A SQL statement string The name of a stored procedure Topic title: Pooling ADO.NET connections in VB.NET 25. The Read method returns the value _____________ when there is no more data to be read in a DataSet. Choose an option below to fill in the blank. Null 0 -1 False True
16
Topic title: Defining an ADO.NET Connection object in VB.NET 26. In which of the following situations is the use of a connected strategy always necessary? Choose more than one option. When you're using a web application that uses ASP.NET When you're modifying database structure True When you're performing operations directly on a database True When you need to read data as XML Topic title: Pooling ADO.NET connections in VB.NET 27. What is the default setting of the ParameterDirection property of a stored-procedure parameter? Choose an option. Input True InputOutput Output ReturnValue Topic title: Architecture of ADO.NET 28. Which of the following collections are encapsulated in the DataSet object? Choose an option. Adapters and Views Commands and Connections Rows, Columns, and Constraints Tables and Relations True Topic title: Distributed data-access requirements 29. In a tiered data-access application, each tier comprises a discrete ____________________. Choose an option below to fill in the blank. application server group of users separated logically section of application functionality True set of application data Topic title: Working with ADO.NET connections in VB.NET 30. The __________________ method returns the number of rows affected by the execution of a DDL command. Choose an option below to fill in the blank. ExecuteScalar ExecuteReader ExecuteXMLReader ExecuteNonQuery True
17
18
System.GC.Collect() forces garbage collector to run. This is not recommended but can be used if situations arise.
What is NameSpace?
Namespace has two basic functionality :NameSpace Logically group types, example System.Web.UI logically groups our UI related features. In Object Oriented world many times its possible that programmers will use the same class name.By qualifying NameSpace with classname this collision is able to be removed.
What is a CTS?
In order that two language communicate smoothly CLR has CTS (Common Type System).Example in VB you have "Integer" and in C++ you have "long" these datatypes are not compatible so the interfacing between them is very complicated. In order to able that two different languages can communicate Microsoft introduced Common Type System. So "Integer" datatype in VB6 and "int" datatype in C++ will convert it to System.int32 which is datatype of CTS. CLS which is covered in the coming question is subset of CTS. If you have undergone COM programming period interfacing VB6 application with VC++ application was a real pain as the datatype of both languages did not have a common ground where they can come and interface, by having CTS interfacing is smooth.
What is a CLR?
Full form of CLR is Common Language Runtime and it forms the heart of the .NET framework. All Languages have runtime and its the responsibility of the runtime to take care of the code execution of the program. For example VC++ has MSCRT40.DLL,VB6 has MSVBVM60.DLL, Java has Java Virtual Machine etc. Similarly .NET has CLR. Following are the responsibilities of CLR ? Garbage Collection :- CLR automatically manages memory thus eliminating memory leaks. When
19
objects are not referred GC automatically releases those memories thus providing efficient memory management. ? Code Access Security :- CAS grants rights to program depending on the security configuration of the machine. Example the program has rights to edit or create a new file but the security configuration of machine does not allow the program to delete a file. CAS will take care that the code runs under the environment of machines security configuration. ? Code Verification :- This ensures proper code execution and type safety while the code runs. It prevents the source code to perform illegal operation such as accessing invalid memory locations etc. ? IL( Intermediate language )-to-native translators and optimizer's :- CLR uses JIT and compiles the IL code to machine code and then executes. CLR also determines depending on platform what is optimized way of running the IL code.
Shashi Ray
20