众所周知,几乎任何一个程序都需要和数据打交道,与数据源进行连接是任何一个程序需要考虑的问题,但是数据源多种多样,常见的有Oracle、SQL Server、记事本、Sybase、IBM DB2、Excel、文本文件、SQLite等等。因此每个开发工具都提供对相应数据源连接的Provider,这些Provider都包含连接字符串属性来与指定数据源进行交互。如此多种多样的连接字符串估计没有人能够都记住。
本人今天在做一个Excel 2010导入到程序DataSet的时候就遇到了连接字符串指定不正确无法正常运行的问题,在网上搜索了一遍,发现了一个非常不错的工具站点:connectionstrings.com/ 含各种连接串介绍,并且包含驱动程序下载,值得收藏。
1、地址:http://www.connectionstrings.com/ ,支持的数据源信息还是相当丰富的,见过的都在,更多的是没见过的。
2、以Excel为例,含有Excel 97 一直到Excel 2013 不同版本的连接串。下面是适用于Excel 2007、Excel 2010 和 Excel 2013,驱动程序为Microsoft ACE OLEDB 12.0的连接串.
Xlsx
files
Connect to
Excel 2007 (and later) files with the Xlsx file extension. That is the Office
Open XML format with macros disabled.
Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=c:\myFolder\myExcel2007file.xlsx;
Extended
Properties="Excel
12.0 Xml;HDR=YES";
"HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite.
Treating data as
text
Use this
one when you want to treat all data in the file as text, overriding Excels
column type "General" to guess what type of data is in the
column.
Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=c:\myFolder\myExcel2007file.xlsx;
Extended
Properties="Excel
12.0 Xml;HDR=YES;IMEX=1";
If you want to read the column headers into the result set (using HDR=NO even though there is a header) and the column data is numeric, use IMEX=1 to avoid crash.
To always use IMEX=1 is a safer way to retrieve data for mixed data columns. Consider the scenario that one Excel file might work fine cause that file‘s data causes the driver to guess one data type while another file, containing other data, causes the driver to guess another data type. This can cause your app to crash.
3、Microsoft ACE OLEDB 12.0下载地址为:
http://www.connectionstrings.com/ace-oledb-12-0/info-and-download/
感叹老外工作的细腻,愿国人加油。