.NET Database interview Q & A Part-1

To test a Web Service you must create a windows application or web application to consume this service? It is True/False?
FALSE

How many classes can a single.NET DLL contain?
Answer1:
As many

Answer2:
One or more

What are good ADO.NET object(s) to replace the ADO Recordset object?
The differences includes
In ADO, the in-memory representation of data is the recordset.
In ADO.net, it is the dataset
A recordset looks like a single table in ADO
In contrast, a dataset is a collection of one or more tables in ADO.net
ADO is designed primarily for connected access
ADO.net the disconnected access to the database is used
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.
In ADO you cant update the database from the recordset. ADO.NET the data adapter allows you to control how the changes to the dataset are transmitted to the database.

On order to get assembly info which namespace we should import?
System.Reflection Namespace

How do you declare a static variable and what is its lifetime? Give an example.
Answer1
static int Myint–The life time is during the entire application.
br> Answer2
The static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object. The static modifier can be used with fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types. In C#, the static keyword indicates a class variable. In VB, the equivalent keyword is Shared. Its scoped to the class in which it occurs.

Example
a. Static int var //in c#.net
b. static void Time( ) //in c#.net

How do you get records number from 5 to 15 in a dataset of 100 records? Write code.
Answer1
DataSet ds1=new DataSet(); String strCon=”data source=IBM-6BC8A0DACEF;initial catalog=pubs;integrated security=SSPI;persist” +” security info=False;user
id=sa;workstation id=IBM-6BC8A0DACEF;packet size=4096?;
String strCom1=”SELECT * FROM employee”;
SqlDataAdapter sqlDa1=new SqlDataAdapter(strCom1,strCon);
ds1.Tables.Add(”employee”);
sqlDa1.Fill(ds1,40,50,ds1.Tables[”employee”].TableName);
DataGrid dg1.DataSource=ds1.Tables[”employee”].DefaultView;
dg1.DataBind();

Answer2
OleDbConnection1.Open()
OleDbDataAdapter1.Fill(DataSet21, 5, 15, “tab”)
This will fill the dataset with the records starting at 5 to 15
.NET Database interview questions

How do you call and execute a Stored Procedure in.NET? Give an example.
Answer1
ds1=new DataSet();
sqlCon1=new SqlConnection(connectionstring);
String strCom1=”byroyalty”;
sqlCom1=new SqlCommand(strCom1,sqlCon1);
sqlCom1.CommandType=CommandType.StoredProcedure;
sqlDa1=new SqlDataAdapter(sqlCom1);
SqlParameter myPar=new SqlParameter(”@percentage”,SqlDbType.Int);
sqlCom1.Parameters.Add (myPar);
myPar.Value=40;
sqlDa1.Fill(ds1);
dg1.DataSource=ds1;
dg1.DataBind();

Answer2
Yes
Dim cn as new OleDbConnection ( “Provider=Microsoft.Jet.OLEDB.4.0;”+ _
“Data Source=C:\Documents and Settings\User\My Documents\Visual Studio Projects\1209\db1.mdb”+ _
“User ID=Admin;”+ _
“Password=;”);
Dim cmd As New OleDbCommand(”Products”, cn)
cmd.CommandType = CommandType.StoredProcedure
Dim da As New OleDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, “Products”)
DataGrid1.DataSource = ds.Tables(”Products”)

What is the maximum length of a varchar in SQL Server?
Answer1
VARCHAR[(n)]
Null-terminated Unicode character string of length n,
with a maximum of 255 characters. If n is not supplied, then 1 is assumed.

Answer2
8000

Answer3
The business logic is the aspx.cs or the aspx.vb where the code is being written. The presentation logic is done with .aspx extention.

How do you define an integer in SQL Server?
We define integer in Sql server as
var_name int

How do you separate business logic while creating an ASP.NET application?
There are two level of asp.net debugging
1. Page level debugging
For this we have to edit the page level debugging enable the trace to true in the line in the html format of the page.
%@ Page Language=”vb” trace=”true”AutoEventWireup=”false” Codebehind=”WebForm1.aspx.vb” Inherits=”WebApplication2.WebForm1?>

2. You can enable the debugging in the application level for this
Edit the following trace value in web.config file
Enable trace enabled=true.

If there is a calendar control to be included in each page of your application, and and we do not intend to use the Microsoft-provided calendar control, how do you develop it? Do you copy and paste the code into each and every page of your application?

Create the Calendar User Control
The control we will create will contain a calendar control and a label which has the corresponding date and time written
Steps are:-

Creating a CalenderControl
1) To begin, open Visual Studio .NET and begin a new C# Windows Control Library.
2) You may name it whatever you like, for this sample the project name will be CalenderControl

Using the Calender Control in a Windows Application
It’s just like adding any other control like a button or a label.
1) First, create a new Windows Application project named: CustomControl.
2) Add a reference to the Calender Control DLL named: CalenderControl.dll.
3) Now you a can customize the Toolbox:
Right-Click the Toolbox> .NET Framework Components> Browse> select the CalenderControl.dll.
4)The Calender Control is now added to the Toolbox and can be inserted in Windows Form as any other control. The control itself will take care of the date display

How can you deploy an asp.net application ?
You can deploy an ASP.NET Web application using any one of the following three deployment options.
a) Deployment using VS.NET installer
b) Using the Copy Project option in VS .NET
c) XCOPY Deployment

Explain similarities and differences between Java and.NET?
Comparing Java and .NET is comparing apples and oranges. Either the question needs to be to compare Java and C# or J2EE and .NET.

What are the XML files that are important in developing an ASP.NET application?
The XML file necessary for the for developing an asp.net application is Web.config

Specify the best ways to store variables so that we can access them in various pages of ASP.NET application?
Declare the variables in Global.aspx

How many objects are there in ASP?
Answer1
8 objects, they are request,response, server,application,session,file, dictionary, textstream.

Answer2
There are 6 objects in ASP.net
a) Server
b) Session
c) Application
d) ObjectContext
e) Response
f) Request

Which DLL file is needed to be registered for ASP?
The dll needed for the ASP.net is SYSTEM.WEB.dll

Is there any inbuilt paging (for example shoping cart, which will show next 10 records without refreshing) in ASP? How will you do pating?
Use DataGrid control which has in-built paging features for the purpose.

What does Server.MapPath do?
Answer1
srver.mappath() maps the path given in the argument to the server’s physical path.

Answer2
It returns the complete(absolute) path of the file used in parameter.

Answer3
It returns a string containing the physical path in the server’s file system that corresponds to the virtual or relative path specified by the Path argument.

Name atleast three methods of response object other than Redirect.
Answer1
a) Response.Clear( )
Clears the content of the current output stream.
b) Response.Close( )
Closes the network socket for the current response.
c) Response.End( )
Stops processing the current request and sends all buffered content to the client immediately.

Answer2
methods of Response is Redirect a. Transfer

Name atleast two methods of response object other than Transfer.
a) Response.ClearContent( )
Clears the content of the current output stream.
b) Response.ClearHeaders( )
Clears the HTTP headers from the current output stream.

What is State?
It is the property of the web forms.
ASP.NET provides four types of state:
Application state
Session state
Cookie state
View state.

Explain differences between ADO and DAO.
dao- can access only access database
ado- can access any databases

How many types of cookies are there?
2 types, persistant and impersistant.

How many types of cookies are there?
Answer1
Two type of cookeies.
a) single valued eg request.cookies(”UserName”).value=”Mahesh”
b)Multivalued cookies. These are used in the way collections are used.
e.g.
request.cookies(”CookiName”)(”UserName”)=”Mahesh”
request.cookies(”CookiName”)(”UserID”)=”ABC003?
rember no value method in multivalued cooki

Answer2
There are two types of cookies:
Session cookies
Persistent cookies

Tell few steps for optimizing (for speed and resource) ASP page/application.
Avoid mixing html code with asp code

Which command using Query Analyzer will give you the version of SQL Server and Operating System?
@@VERSION
Returns version, processor architecture, build date, and operating system for the current installation of SQL Server.

How to find the SQL server version from Query Analyser
Answer1
To determine which version of Microsoft SQL Server 2005 is running, connect to SQL Server 2005 by using SQL Server Management Studio, and then run the following Transact-SQL statement:
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)
The results are:
• The product version (for example, “9.00.1399.06?)
. • The product level (for example, “RTM”).
• The edition (for example, “Enterprise Edition”).
For example, the result looks similar to:
9.00.1399.06 RTM Enterprise Edition

How to determine which version of SQL Server 2000 is running
To determine which version of SQL Server 2000 is running, connect to SQL Server 2000 by using Query Analyzer, and then run the following code:
SELECT SERVERPROPERTY(’productversion’), SERVERPROPERTY (’productlevel’), SERVERPROPERTY (’edition’)
The results are:
• The product version (for example, 8.00.534).
• The product level (for example, “RTM” or “SP2?).
• The edition (for example, “Standard Edition”). For example, the result looks similar to
:
8.00.534 RTM Standard Edition

Answer2
One can also use SELECT @@Version where the result would look like
Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Express Edition on Windows NT 5.1 (Build 2600: Service Pack 2)

Using query analyzer, name 3 ways you can get an accurate count of the number of records in a table.
Answer1.
a. Select count(*) from table1
b. SELECT object_name(id) ,rowcnt FROM sysindexes WHERE indid IN (1,0) AND OBJECTPROPERTY(id, ‘IsUserTable’) = 1
c. exec sp_table_validation @table = ‘authors’

Answer2.
SELECT count( * ) as totalrecords FROM employee
This will display total records under the name totalrecords in the table employee
use COUNT_BIG
Returns the number of items in a group.
@@ROWCOUNT
Returns the number of rows affected by the last statement.
Use this statement after an SQL select * statement, to retrieve the total number of rows in the table

NEXT-->

Cant Find The Interview Questions u r Looking For ? Search Here