Configuring connection to a Text File (ADO.NET)

Configuring connection to a Text File (ADO.NET)

The .NET OLE DB provider can read records from and insert records into a text file data source using the Microsoft Access database engine (ACE) driver. The ACE driver can access other database file formats through Indexed Sequential Access Method (ISAM) drivers specified in the Extended Properties attribute of the connection.

Following code sample show how to access text file data in .Net :

            string connectString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=..\..\..\;" +
"Extended Properties=\"text;HDR=yes;FMT=Fixed\";";

using (OleDbConnection connection = new OleDbConnection(connectString))
{
connection.Open();
Console.WriteLine("Connection.State : {0}", connection.State);
Console.WriteLine("Connection.Provider : {0}", connection.Provider);
Console.WriteLine("Connection.ServerVersion : {0}", connection.ServerVersion);
}
Console.ReadLine();

Note: Only the directory for the text file is specified in the connection string. The filename of the text file is specified in the T-SQL commands that access data in the text file, similar to a table name in a database.

Output :

TextConnection.bmp