Using OPENROWSET to import a textfile

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tezza98
    New Member
    • Mar 2007
    • 38

    Using OPENROWSET to import a textfile

    Help please, im trying to use open OPENROWSET to import a csv file into my database
    Here is the code im using


    Code:
    --Read CSV using OpenRowSet
    select * from OpenRowset('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)};
      DefaultDir=D:\MSSQL\Data\FUELBCP\;','select top 6 * from
    TRANS.csv')
    and i get this error

    OLE DB error trace [OLE/DB Provider 'MSDASQL' IColumnsInfo::G etColumnsInfo returned 0x80004005: The provider did not give any information about the error.].
    Msg 7399, Level 16, State 1, Line 1
    OLE DB provider 'MSDASQL' reported an error. The provider did not give any information about the error.


    I am using OPENROWSET because i can the compare the text file to a table and the update the table base on what is in the text file but not in the table

    If anyone knows why i am getting this error please put me out of my misery and help me out

    Thanks
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    I am not in a position to solve your problem but try to select not * but one column, then add one column at a time. It looks like top row that has column headers have invalid character or maybe just extra space or tab between columns which is enough to make server confused.

    Good Luck.

    Comment

    • tezza98
      New Member
      • Mar 2007
      • 38

      #3
      I found the soultion and here it is
      It works perfectly

      Code:
      OPENROWSET('Microsoft.Jet.OLEDB.4.0',
      'Text;Database=\\w2ks1\MSSQL\DATA\FUELBCP',
      'select  * from TRANS.csv')

      Comment

      Working...