Interview Tips Interview Tips, Interview Questions and Answers

21Feb/120

FIX: Error message when you run a “BULK INSERT” statement on a table that does not have a clustered index in SQL Server 2005 or SQL Server 2008: “spid1005 Error: 5243, Severity: 22, State: 1 An i …

Symptoms
Consider the following scenario:In Microsoft SQL Server 2005 or Microsoft SQL Server 2008, you have a table that does not have a clustered index. You run a BULK INSERT statement on this table.In this scenario, you may receive the following error message in the SQL Servererror log file:

<Date><Time> spid1005Error: 5243, Severity: 22, State: 1.
<Date><Time>2009-02-13 03:26:46.09 spid1005An inconsistency was detected during an internal operation.
<Date><Time>Please contact technical support. Reference number 8.
Additionally, a mini-dump file is generated in the SQL Server log folder.
Note This problem may occur when you run a BULK INSERT statement on a table in a database that is used by Microsoft SharePoint.
Resolution
SQL Server 2005 Service Pack 2 (SP2)Important You must use this fix if you are running SQL Server 2005 Service Pack 2 (SP2).
The fix for this issue was first released in Cumulative Update15 for SQL Server 2005 Service Pack 2. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
972510?(http://support.microsoft.com/kb/972510/LN/) Cumulative update package 15 for SQL Server 2005 Service Pack 2Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2005 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
937137?(http://support.microsoft.com/kb/937137/LN/) The SQL Server 2005 builds that were released after SQL Server 2005 Service Pack 2 was releasedMicrosoft SQL Server 2005hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2005 Service Pack 2 hotfix to an installation of SQL Server 2005 Service Pack 2. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack. SQL Server 2005 Service Pack 3 (SP3)Important You must use this fix if you are running SQL Server 2005 Service Pack 3 (SP3).
The fix for this issue was first released in Cumulative Update5 for SQL Server 2005 Service Pack 3. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
972511?(http://support.microsoft.com/kb/972511/LN/) Cumulative update package 5 for SQL Server 2005 Service Pack 3Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2005 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
960598?(http://support.microsoft.com/kb/960598/LN/) The SQL Server 2005 builds that were released after SQL Server 2005 Service Pack 3 was releasedMicrosoft SQL Server 2005hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2005 Service Pack 3 hotfix to an installation of SQL Server 2005 Service Pack 3. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack. SQL Server 2008Important You must use this fix if you are running the release version of SQL Server 2008.
The fix for this issue was first released in Cumulative Update 7. For more information about how to obtain this cumulative update package for SQL Server 2008, click the following article number to view the article in the Microsoft Knowledge Base:
973601?(http://support.microsoft.com/kb/973601/) Cumulative update package 7 for SQL Server 2008Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
956909?(http://support.microsoft.com/kb/956909/) The SQL Server 2008 builds that were released after SQL Server 2008 was releasedSQL Server 2008 Service Pack 1 (SP1)Important You must use this fix if you are running SQL Server 2008 Service Pack 1 (SP1).
The fix for this issue was first released in Cumulative Update4 for SQL Server 2008 Service Pack 1. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
973602?(http://support.microsoft.com/kb/973602/LN/) Cumulative update package 4 for SQL Server 2008 Service Pack 1Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
970365?(http://support.microsoft.com/kb/970365/LN/) The SQL Server 2008 builds that were released after SQL Server 2008 Service Pack 1 was releasedMicrosoft SQL Server 2008hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2008 Service Pack 1 hotfix to an installation of SQL Server 2008 Service Pack 1. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack.

9Feb/120

Error message when you try to install SQL Server 2008 if the path of the SQL Server 2008 installation media contains a number sign (#) character: “Could not load file or assembly ‘<Path>\Mi …

Symptoms
When you try to install Microsoft SQL Server 2008 from a local path or from a network path, you receive the following error message:

Could not load file or assembly 'Path\Microsoft.SQL.Chainer.PackageData.dll' or one of its dependencies. The system cannot find the file specified.This issue occurs if the path of the SQL Server 2008 installation media contains a number sign (#) character.
Additionally, the following error message is logged in the Detail_GlobalRules.txt file:

Date Time Slp: Log provider 'Microsoft.SqlServer.Chainer.Infrastructure.LogProviderFile' has been registered
Date Time Slp: Log provider 'Microsoft.SqlServer.Chainer.Infrastructure.LogProviderStatus' has been registered
Date Time Slp: Received request to add the following file to Watson reporting: C:\Documents and Settings\Administrator\Local Settings\Temp\tmpDC5.tmp
Date Time Slp: The following is an exception stack listing the exceptions in outermost to innermost order
Date Time Slp: Inner exceptions are being indented
Date Time Slp:
Date Time Slp: Exception type: Microsoft.SqlServer.Chainer.Infrastructure.ChainerInfrastructureException
Date Time Slp:Message:
Date Time Slp:Could not load file or assembly '<Path>\Microsoft.SQL.Chainer.PackageData.dll' or one of its dependencies. The system cannot find the file specified.
Date Time Slp:Stack:
Date Time Slp:at Microsoft.SqlServer.Chainer.Infrastructure.ExtensionService.RegisterExtension(String extensionId, String name, String path)
Date Time Slp:at Microsoft.SqlServer.Chainer.Setup.Setup.LoadPackageXML(ServiceContainer context)
Date Time Slp:at Microsoft.SqlServer.Chainer.Setup.Setup.Run()
Date Time Slp:at Microsoft.SqlServer.Chainer.Setup.Setup.Start()
Date Time Slp:at Microsoft.SqlServer.Chainer.Setup.Setup.Main()
Date Time Slp:Inner exception type: System.IO.FileNotFoundException
Date Time Slp:Message:
Date Time Slp:Could not load file or assembly <Path>\Microsoft.SQL.Chainer.PackageData.dll' or one of its dependencies. The system cannot find the file specified.
Date Time Slp:Stack:
Date Time Slp:at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
Date Time Slp:at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
Date Time Slp:at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
Date Time Slp:at System.Reflection.Assembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, StackCrawlMark& stackMark)
Date Time Slp:at System.Reflection.Assembly.LoadFrom(String assemblyFile)
Date Time Slp:at Microsoft.SqlServer.Chainer.Infrastructure.ExtensionService.RegisterExtension(String extensionId, String name, String path)
Date Time Slp: The following exception occurred while preparing status logs during Watson failure processing: /Datastore/InputSettings
Date Time Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\Microsoft SQL Server to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\DateTime\Registry_SOFTWARE_Microsoft_Microsoft SQL Server.reg_
Date Time Slp: Sco: Unable to write hklm registry key SOFTWARE\Microsoft\Microsoft SQL Server to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\DateTime\Registry_SOFTWARE_Microsoft_Microsoft SQL Server.reg_, Win32 error 2
Date Time Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\DateTime\Registry_SOFTWARE_Microsoft_Windows_CurrentVersion_Uninstall.reg_
Date Time Slp: Sco: Attempting to write hklm registry key SOFTWARE\Microsoft\MSSQLServer to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\DateTime\Registry_SOFTWARE_Microsoft_MSSQLServer.reg_
Date Time Slp: Sco: Unable to write hklm registry key SOFTWARE\Microsoft\MSSQLServer to file C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Log\DateTime\Registry_SOFTWARE_Microsoft_MSSQLServer.reg_, Win32 error 2
Date Time Slp: Could not load file or assembly '<Path>\Microsoft.SQL.Chainer.PackageData.dll' or one of its dependencies. The system cannot find the file specified.
Date Time Slp: Watson bucket for exception based failure has been created
Date Time Slp: Sco: Attempting to create base registry key HKEY_LOCAL_MACHINE, machine
Date Time Slp: Sco: Attempting to open registry subkey Software\Microsoft\PCHealth\ErrorReporting\DW\Installed
Date Time Slp: Sco: Attempting to get registry value DW0200
Date Time Slp: Submitted 1 of 1 failures to the Watson data repository
Date Time Slp:
Date Time Slp: ----------------------------------------------------------------------
Date Time Slp:
Date Time Slp: Error result: -2068774911
Date Time Slp: Result facility code: 1201
Date Time Slp: Result error code: 1
Resolution
This issue occurs because the Setup program cannot load an assembly from the path of the SQL Server 2008 installation media if the pathcontains a number sign (#) character.

20Oct/100

Shrinking Session State in asp.net

ASP.NET provides two default options for storing session state across a Web farm: a session-state provider that invokes an out-of-process session-state server, and a session-state provider that stores data in a Microsoft SQL Server database. Because both options involve storing state information outside a Web application's worker process, session state has to be serialized before it is sent to remote storage. Depending on how much information a developer saves in session state, the size of the serialized data can grow quite large.

ASP.NET 4 introduces a new compression option for both kinds of out-of-process session-state providers. When the compressionEnabled configuration option shown in the following example is set to true, ASP.NET will compress (and decompress) serialized session state by using the .NET Framework System.IO.Compression.GZipStream class.

mode="SqlServer"
sqlConnectionString="data source=dbserver;Initial Catalog=aspnetstate"
allowCustomSqlDatabase="true"
compressionEnabled="true"
/>

With the simple addition of the new attribute to the Web.config file, applications with spare CPU cycles on Web servers can realize substantial reductions in the size of serialized session-state data.

4Oct/100

ADO.NET Entity Framework

The ADO.NET Entity Framework is an ORM (Object Relational Mapping) tool and is Microsoft’s main data access strategy moving forward. Microsoft released version 1 with Visual Studio 2008 SP1 with the .NET Framework 3.5 SP1. They released version 4 with Visual Studio 2010 and the .NET Framework version 4. The product team decided to sync the version number with the version of the .NET Framework. You may see references to v1 as Entity Framework v3.5 as well as v1 to reflect this.

ORM tools allow you to work with your relational database in a way that makes more sense to you as a developer and doesn’t require you to hand code SQL (which is something I don’t think many developers ever actually want to do on a regular basis). You work with a set of objects in your application that represent the database and an ORM tool will generate dynamic SQL that is sent to the database and executed. I have heard it said that ORM tools have an 80/20 use ratio, meaning that on average an ORM tool will solve 80% of your database access issues and the other 20% will likely need to be done with stored procedures or some other method. I think this is a solid ratio, but the ratio tends to be more like 95/5 for me. The real ratio will ultimately depend on the type of applications that you write. For quite a few of the projects I work on, the Entity Framework solves 100% of my data access problems. On average, I would say that just by using an ORM, my data access development time is cut by at least 75%. Since the ORM tool handles all of my CRUD (Create Read Update Delete) operations, I don’t have to write and debug SQL code for basic data access. This is, of course, the beauty of ORM in general and the Entity Framework fills this space nicely.

27Mar/100

Database Interview Question: What is Index Tuning?

One of the hardest tasks facing database administrators is the
selection of appropriate columns for non-clustered indexes. You should
consider creating non-clustered indexes on any columns that are
frequently referenced in the WHERE clauses of SQL statements. Other
good candidates are columns referenced by JOIN and GROUP BY operations.
You may wish to also consider creating non-clustered indexes that
cover all of the columns used by certain frequently issued queries.
These queries are referred to as "covered queries" and experience
excellent performance gains.
Index Tuning is the process of finding appropriate column for
non-clustered indexes.
SQL Server provides a wonderful facility known as the Index Tuning
Wizard which greatly enhances the index selection process.

26Mar/100

C# Interview Questions, Part 3

41. What’s the difference between // comments, /* */ comments and /// comments? Single-line, multi-line and XML documentation comments.

42. How do you generate documentation from the C# file commented properly with a command-line compiler? Compile it with a /doc switch.

43. What’s the difference between and XML documentation tag? Single line code example and multiple-line code example.

44. Is XML case-sensitive? Yes, so and are different elements.

45. What debugging tools come with the .NET SDK? CorDBG – command-line debugger, and DbgCLR – graphic debugger. Visual Studio .NET uses the DbgCLR. To use CorDbg, you must compile the original C# file using the /debug switch.

46. What does the This window show in the debugger? It points to the object that’s pointed to by this reference. Object’s instance data is shown.

47. What does assert() do? In debug compilation, assert takes in a Boolean condition as a parameter, and shows the error dialog if the condition is false. The program proceeds without any interruption if the condition is true.

48. What’s the difference between the Debug class and Trace class? Documentation looks the same. Use Debug class for debug builds, use Trace class for both debug and release builds.

49. Why are there five tracing levels in System.Diagnostics.TraceSwitcher? The tracing dumps can be quite verbose and for some applications that are constantly running you run the risk of overloading the machine and the hard drive there. Five levels range from None to Verbose, allowing to fine-tune the tracing activities.

50. Where is the output of TextWriterTraceListener redirected? To the Console or a text file depending on the parameter passed to the constructor.

51. How do you debug an ASP.NET Web application? Attach the aspnet_wp.exe process to the DbgClr debugger.

52. What are three test cases you should go through in unit testing? Positive test cases (correct data, correct output), negative test cases (broken or missing data, proper handling), exception test cases (exceptions are thrown and caught properly).

53. Can you change the value of a variable while debugging a C# application? Yes, if you are debugging via Visual Studio.NET, just go to Immediate window.

54. Explain the three services model (three-tier application). Presentation (UI), business (logic and underlying code) and data (from storage or other sources).

55. 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. OLE-DB.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.

56. What’s the role of the DataReader class in ADO.NET connections? It returns a read-only dataset from the data source when the command is executed.

57. What is the wildcard character in SQL? Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.

58. Explain ACID rule of thumb for transactions. Transaction must be Atomic (it is one unit of work and does not dependent on previous and following transactions), Consistent (data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t), Isolated (no transaction sees the intermediate results of the current transaction), Durable (the values persist if the data had been committed even if the system crashes right after).

59. What connections does Microsoft SQL Server support? Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and passwords).

60. 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.

61. Why would you use untrusted verificaion? Web Services might use it, as well as non-Windows applications.

62. What does the parameter Initial Catalog define inside Connection String? The database name to connect to.

63. What’s the data provider name to connect to Access database? Microsoft.Access.

64. What does Dispose method do with the connection object? Deletes it from the memory.

65. What is a pre-requisite for connection pooling? Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings.

6Jan/100

ADO.NET and Database Questions

    1. What is the wildcard character in SQL?Polyglot_Programming_Languages
      Let’s say you want to query database with LIKE for all employees whose name starts with La. The wildcard character is %, the proper query with LIKE would involve ‘La%’.
    2. What is the role of the DataReader class in ADO.NET connections?
      It returns a read-only, forward-only rowset from the data source.  A DataReader provides fast access when a forward-only sequential read is needed.
    3. 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. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix. OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET.
    4. What connections does Microsoft SQL Server support?
      Windows Authentication (via Active Directory) and SQL Server authentication (via Microsoft SQL Server username and password).
    5. 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.
    6. What does the Dispose method do with the connection object?
      Deletes it from the memory.
      To Do: answer better. The current answer is not entirely correct.
    7. What is a pre-requisite for connection pooling?
      Multiple processes must agree that they will share the same connection, where every parameter is the same, including the security settings. The connection string must be identical.
    8. What does the Initial Catalog parameter define in the connection string?
      The database name to connect to.
    9. Explain ACID rule of thumb for transactions.
      A transaction must be:
      1. Atomic - it is one unit of work and does not dependent on previous and following transactions.
      2. Consistent - data is either committed or roll back, no “in-between” case where something has been updated and something hasn’t.
      3. Isolated - no transaction sees the intermediate results of the current transaction).
      4. Durable - the values persist if the data had been committed even if the system crashes right after.
3Jan/100

.NET Interview Questions on CLR

Overview of CLR integration.
The CLR (Common Language Runtime) integration is hosted in the Microsoft SQL Server 2005.
With CLR integration, stored procedures, triggers, user- defined functions, user-defined types, and user-defined aggregates in managed code, etc can be written.
As managed code compiles to native code before executing, significant performance can be achieved.
The SQL Server acts as an operating system for the CLR when it is hosted inside SQL Server.

Following are the steps to build a CLR stored procedure in SQL Server 2005

    * Enable CLR integration in SQL Server 2005
    * Create a CLR stored procedure Assembly
    * Deploy the Assembly in SQL Server 2005
    * Create and execute the CLR stored procedure in SQL Server 2005

Explain CLR in brief.
CLR stands for Common Language Runtime. The CLR is a development platform. It provides a runtime, defines functionality in some libraries, and supports a set of programming languages. The CLR provides a runtime so that the softwares can utilize its services. The CLR Base Class Library allows interaction with the runtime. The CLR supports various programming languages, several standards and is itself been submitted as an open standard.  

Describe the parts of assembly.
An assembly is a partially compiled code library. In .NET, an assembly is a portable executable and can be an EXE (process assembly) or a DLL (library assembly). An assembly can consist of one or more files or modules in various languages. It is used in deployment, versioning and security.