TSQL to import Excel sheet

  • Hello comunity

    i have the following TSQL Command :

    SELECT * INTO CU FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',

    'Excel 8.0;Database=C:\prov\EXTRUVERDE_CCustos e Naturezas_Final para importar_JALVES.xls', [DBEXT$])

    But , SQL server return this error, how to resolve :

    Msg 15281, Level 16, State 1, Line 3

    SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Ad Hoc Distributed Queries' by using sp_configure.

    For more information about enabling 'Ad Hoc Distributed Queries', see "Surface Area Configuration" in SQL Server Books Online.

  • You need to go into SQL Server Surface Area Configuration and then into Surface Area Configuration for Features and check the enable Openrowset and Opendatasource support selection under Ad Hoc Remote Queries. This is disabled by default in SQL Server 2005.

  • Thanks Jack

    I will try

    Luis Santos

  • Hello Jack

    I make what you said in your last reply , but now i have an another error:

    Msg 7399, Level 16, State 1, Line 1

    The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" reported an error. The provider did not give any information about the error.

    Msg 7303, Level 16, State 1, Line 1

    Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

    What the problem now, could you give me.

    Thanks

    Luis Santos

  • Hello comunity

    I read on google, many persons that have the same problem, but any response reolve them.

    Could someone give me a little help.

    Note : my OS is Windows Vista an i have Office 2007 professional

    Many thanks again

    Luis Santos

  • You need to enable OLE DB from Surface area configuration. Restart SQL Server services and it should work.

  • Hi this type of error will occur for differen reasons.

    check if your Filename and path is correct.

    Ensure that there is no spell mistakes.

    if your file name database path is correct verify your connection string

    if your connection is correct then verify there are no of columns in excel and sql server is correct.

    if no of columns in excel and sql server then

    verify if your excel is open.if it is opened just close the excel. and run the quey

    Malleswarareddy
    I.T.Analyst
    MCITP(70-451)

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

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