June 29, 2015
Hot Topics:

Managed Extensions: Using the .NET ODBC Classes to Read Text Data

  • September 14, 2004
  • By Tom Archer
  • Send Email »
  • More Articles »

Taking Control of the Process with the schema.ini File

Once you've started working with text files via a DSN-less connection, you might run into situations that will have you asking things like "How do I specify how the file is delimited (e.g., tab vs. comma)?" or "Where can I specify the character set?" These settings and more can be specified via a very simple file named schema.ini that resides in the same directory as the data file. The schema.ini file is documented on the Microsoft Web site so I won't attempt to cover every possible parameter that can be specified. However, I will cover the most popular question I see on the Internet: how to specify if the data includes (as its first row) the column names of the data.

By default, the text driver assumes that the data contains a column heading row. Therefore, if your data does not contain this row and you do not define a schema.ini file, you will find that the first row of data being ignored. For example, if your data looked like the following, the reader code above would display only the second and third records (leaving out your favorite author!):

Tom Archer,Archer Consulting Group
Bradley Jones,Jupitermedia
Bill Gates,Microsoft
In order to specify that the data does not include a column row and that you don't wish to name the columns, your schema.ini file would look like the following:

data file

In terms of specifying the column names for your data, you have two choice: The column name can be retrieved from the reader using the OdbcDataReader::GetName method. This article's demo application uses the last technique and—while being very simple in scope—allows you to tinker with your data file and schema.ini file so that you can easily test the various configuration combinations until you get it right for your particular application.

Download the Code

To download the accompanying source code for this article, click here.

About the Author

The founder of the Archer Consulting Group (ACG), Tom Archer has been the project lead on three award-winning applications and is a best-selling author of 10 programming books as well as countless magazine and online articles.

Page 2 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel