Loading data from Excel file into SQL table

  • Hello everyone,

    I have an Excel file with just one field and it contains numbers. I want to read the Excel file into a table in SQL Server. I have tried to use

    select * into tablename

    FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=D:\testing.xls;HDR=YES', 'SELECT * FROM [Sheet1$]')

    However I am unsuccessful because I get the following error

    Msg 7308, Level 16, State 1, Line 2

    OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.

    Can you please help me out. I dont want to use SSIS. All I want is T-SQL.

    Thank you all in advance.

  • Junglee_George (1/13/2011)


    Hi

    Try this useful link

    http://beyondrelational.com/blogs/madhivanan/archive/2007/08/27/import-export-to-excel.aspx%5B/quote%5D

    :ermm:

    Did you read the original question? The link you provided just explains how to import data from excel using the OPENROWSET command. The OP has already done that, there is a problem with the provider.

    @divya-2: check if distributed queries are enabled in your db:

    EXEC sp_configure 'ad hoc distributed queries'

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Just curious, have you tried using the Import Data Wizard? I'm not sure it will meet your needs or not, but you can frequently get a lot more error information out of that than with OPENROWSET. It might help, just to try.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Here are the steps to allow distributed ad hoc queries:

    sp_configure 'show advanced options', 1

    reconfigure

    sp_configure 'Ad Hoc Distributed Queries', 1

    reconfigure with override

    This should handle the problem.

    Todd Fifield

  • Hi all,

    sp_configure 'show advanced options', 1

    reconfigure

    sp_configure 'Ad Hoc Distributed Queries', 1

    reconfigure with override

    With this script I was able to read from the Excel file. Thank you all for helping me..

  • Divya,

    Glad to be of help.

    Todd Fifield

  • Hi all,

    I've checked my configuration with sp_configure and 'Ad Hoc Distributed Queries' value is 1.

    And when I exec my script to import Excel data into SQL table it returns this:

    Msg 7308, Level 16, State 1, Line 2

    OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.

    The syntax is OK and the Configuration too. So, Why I'm getting that error message?

    Thanks in advance.

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply