string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\JohnDoe\Documents\Northwind.mdb"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); string dataSourceName = connection.GetDataSourcePropertyValue("Data Source").ToString(); Console.WriteLine("Data source name: " + dataSourceName); }
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\JaneSmith\Documents\Customers.xlsx;Extended Properties='Excel 12.0 Xml;HDR=YES;IMEX=1;'"; using (OleDbConnection connection = new OleDbConnection(connectionString)) { connection.Open(); int maxRows = (int)connection.GetDataSourcePropertyValue("Maximum Rows"); Console.WriteLine("Maximum rows allowed: " + maxRows); }This example connects to an Excel workbook and retrieves the Maximum Rows property value, which is the maximum number of rows that can be accessed from the data source. The output will display the maximum rows allowed. Package library: System.Data.OleDb.