Search code examples
vb.netoledb

OleDB ' Unspecified error' VB


I am using oledb to get data from .txt file and i have encountered error.

Dim oleDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\CompName\C$\Path;ExtendedProperties="Text;HDR=Yes;FMT=Fixed""

where CompName and Path are real values

I get Unspecified error in adapter fill

Using connection As New OleDbConnection(oleDb)
        Using command As New OleDbCommand(sql, connection)
            Using adapter As New OleDbDataAdapter(command)
                adapter.Fill(s)
            End Using
        End Using
    End Using
    Return s
End Function

anyone tried geting data across intranet from different computer using oledb?


Solution

  • To use the OleDb Text Driver with a text file formatted with fixed length columns you need to have a SCHEMA.INI file in the same folder where the text files are located.
    The SCHEMA.INI allows to define various property for the text file like Format, Field Names, Widths and Types, character sets and some conversion rules.

    From MSDN

    When the Text driver is used, the format of the text file is determined by using a schema information file. The schema information file is always named Schema.ini and always kept in the same directory as the text data source. The schema information file provides the IISAM with information about the general format of the file, the column name and data type information, and several other data characteristics. A Schema.ini file is always required for accessing fixed-length data. You should use a Schema.ini file when your text table contains DateTime, Currency, or Decimal data, or any time that you want more control over the handling of the data in the table.

    More details about the SCHEMA.INI file could be found on this MSDN page