• 各种连接字符串


    众所周知,几乎任何一个程序都需要和数据打交道,与数据源进行连接是任何一个程序需要考虑的问题,但是数据源多种多样,常见的有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:myFoldermyExcel2007file.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:myFoldermyExcel2007file.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.

     3Microsoft ACE OLEDB 12.0下载地址为:

    http://www.connectionstrings.com/ace-oledb-12-0/info-and-download/

     

    感叹老外工作的细腻,愿国人加油。

  • 相关阅读:
    bzoj 3196/tyvj p1730 二逼平衡树
    AW201 可见的点 (欧拉函数)
    P3912 素数个数
    P1029 最大公约数和最小公倍数问题
    P1835 素数密度
    P2563 [AHOI2001]质数和分解
    P1075 质因数分解
    AW199 余数之和
    AW198 反素数
    AW197 阶乘分解
  • 原文地址:https://www.cnblogs.com/hangwq/p/3526502.html
Copyright © 2020-2023  润新知