Import Data from Excel with T-SQL

Here are the two examples of importing data from Excel into SQL Server using T-SQL: both tecniques use the OPENROWSET function:

--Excel 97-2003
SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;HDR=YES;IMEX=1;Database=C:\MyExcel.xls', 'SELECT * FROM [Sheet1$]')

--Excel 2007-2010
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0 Xml;HDR=YES;IMEX=1;Database=C:\MyExcel.xlsx', 'SELECT * FROM [Sheet1$]')

If you are unable to use the OPENROWSET function, you need to do the following:

sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO

sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO

StackOverflow When Using SlSvcUtil.exe

If you are using SlSvcUtil.exe from Silverlight 4 SDK and you get a StackOverflowException, probably it is because of a known bug of the application.
The solution found in the article Workaround for StackOverflowException when using SlSvcUtil.exe is to add a C:\Program Files\Microsoft SDKs\Silverlight\v4.0\Tools\SlSvcUtil.exe.config file with the following content:

<configuration>
  <satelliteassemblies>
    <assembly name="SlSvcUtil, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </satelliteassemblies>
</configuration>