Solved

Import CSV into Sql Server with OPENROWSET

Posted on 2010-08-16
1
1,077 Views
Last Modified: 2012-05-10
I'm trying to import a simple .csv into Sql Server 8 with OPENROWSET:

Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\IMPORTFILES\test.csv', 'SELECT * FROM [Sheet1$]')

I get the following error:

Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error. The provider did not give any information about the error.
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IDBInitialize::Initialize returned 0x80004005:  The provider did not give any information about the error.].

I have verified the .csv file is valid and can be opened in Excel.  I've done this is the past without errors, can't see what's wrong this time.
0
Comment
Question by:kevbob650
1 Comment
 
LVL 7

Accepted Solution

by:
macentrap earned 500 total points
ID: 33450580
You are using .csv wont you be using Microsoft Text Driver??


SELECT * FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};DEFAULTDIR=C:\IMPORTFILES\;Extensions=CSV;','SELECT * FROM test.csv')

With Excel I have used please try to add IMEX=1

I have used this in SQL 2008
UPDATE SL1
SET
SL1.QTY = T1.QTY                  

FROM  

(select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',

'Excel 8.0;DATABASE=D:\qty.xls;IMEX=1','Select * from [Results$]'))AS T1,

Stock SL1
WHERE
T1.Code COLLATE DATABASE_DEFAULT  = SL1.Code COLLATE DATABASE_DEFAULT
and T1.Loc  = SL1.Loc
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now