none
win7中SQL语句 RRS feed

  • 问题

  • Excel导入SQL Server,用ADO连接的是要导入的Excel。
    Excel位置'C:\e.xls',已连接上,并读出sheet页,语句读 
    select * from [sheet1$]。在XP下没问题,在Win7下报错,不可识别的数据库格式'C:\e.xls'。
    不兼容吗?需要改成什么样子呢?
    • 已移动 Jie Bao 2011年5月20日 7:26 (发件人:Windows 应用程序兼容性)
    2011年5月17日 7:34

答案

  • 谢谢。尝试不可以。查到原因了。
    在win7中,ADO,Open后,ConnectionString变化了。并且丢失了连接的是Excel信息,以office 2003为例,丢了Extended Properties="Excel 8.0; HDR=NO;IMEX=1;"。XP不会出现丢失现象。用时,把丢失信息补充上就行了。

    2011年5月24日 4:58

全部回复

  • 不是操作系统层面的兼容性问题,是具体SQL Server上的。请问你用的是什么版本的SQL Server? 你有没有在Win7上安装Office Excel,是具体什么版本?

    我测试了SQL Server 2008 和 2008 R2 两个版本去导入一个Excel 97-2003格式的xls文件,在Windows XP, 7 和 2008 Server R2下, 这个SQL都是可以工作的。

    所以我觉得 “不可识别数据库类型”是不是和你选择的ADO连接有关, (顺便提一句,我测试用的 Microsoft Excel 连接Data Source), 你可以把你的 ADO 的具体配置贴出来,我们看下;还有,你要确保在你的Windows 7中,ADO连接器可以访问Excel类型的文件的。

    对了,还有要提示一下的,Windows 7会用UAC保护C盘,默认情况下必须是 run as administrator 的进程才可以访问,所以你要尝试把你的SQL Server “Run as Administrator”, 或者把你的e.xls放到其它分区再试试。

     

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年5月18日 9:34
  • 首先谢谢版主。机器sql server 2000,sp3补丁。office2003,office2007均试过。

    sql server直接导入没有问题。编写代码用ADO连接的不行。

    可能象您说的是ADO连接问题。ADO和win7不兼容性吗?ADO在win7下可以连接access,excel,sql server等。

    但目前遇到就是excel出问题了。并且以管理员身份运行的程序。连接excel是成功的。因为已经读出excel中的sheet页签,就是

    使用这种方式读内容时“select * from [sheet1$]”,出问题了。报“不可识别的数据库格式”。XP是可以的。

    目前Microsoft Data Access Components (MDAC) 2.8驱动已经装了。依然问题存在。


    2011年5月19日 1:40
  • 煮一下大小写,用[Sheet1$]。

    还有,确保你安装的Office 是32位,使用32位的导入功能。


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年5月19日 9:44
  • 大小写是正确的。我把sheet页签改成和程序读出来一致。

    安装win7是32位的。 Office有32,64位吗?安装默认的。应该是32位的。

    2011年5月20日 1:20
  • 你好,

    有个建议, 你可以用ADO开发一个例子去用 select * from [sheet1$] 读取下你的xls文件。我尝试了许多情况,都没有发现这个问题。我把它移到SQL Server那边看看有没有进一步信息吧

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年5月20日 7:26
  • 谢谢。sql server问题吗?总感觉是win7兼容,或需要安装什么驱动,或设置什么的问题.
    2011年5月23日 4:38
  • 因为操作系统只是提供一系列API可以让各种应用程序能正常地运行工作,你的问题是围绕SQL执行的。操作系统本身是不带SQL执行能力的,这个问题关系到SQL Server 2000中的ADO在导入时的问题,我尝试重现,在Windows 7是好的,我这边测试了各版本的ADO,都可以解析[Sheet1$]。

    你尝试过下面的这个了吗:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=C06B8369-60DD-4B64-A44B-84B371EDE16D

    还有:http://www.microsoft.com/downloads/en/details.aspx?FamilyID=78CAC895-EFC2-4F8E-A9E0-3A1AFBD5922E


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年5月23日 11:11
  • 谢谢。尝试不可以。查到原因了。
    在win7中,ADO,Open后,ConnectionString变化了。并且丢失了连接的是Excel信息,以office 2003为例,丢了Extended Properties="Excel 8.0; HDR=NO;IMEX=1;"。XP不会出现丢失现象。用时,把丢失信息补充上就行了。

    2011年5月24日 4:58
  • 赞! 原来如此。是不是你忘了在  Extended Properties="Excel 8.0; HDR=NO;IMEX=1;"  外面再加一层引号。

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2011年5月24日 5:41