2015-04-07 73 views
1

我想本地的SQL Express服务器上执行下面的SQL脚本的执行SQL:从SQL Express的从VBScript

Select * 
from OPENROWSET('Microsoft.ACE.OLEDB.12.0', 
'Excel 12.0;HDR=YES;Database=C:\localpath\file.xlsx;', 
[Sheet1$]) 

查询运行工作正常。但是,当我试图从VBScript运行:

dim dbconn, ConnectionString 
ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=compname\SQLEXPRESS;Database=DB;ID=username;Password="";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;" 
Set dbconn = CreateObject("ADODB.Connection") 
dbconn.Open ConnectionString 
dbconn.Execute("\\path\query.sql") 

它会显示以下错误:

Script: Script path
Line: 4
Char: 1
Error: Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
Code: 800A0BB9
Source: ADODB.Connection

回答

1

正确的连接字符串:

ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbname;Data Source=compname\SQLEXPRESS" 
1

难道你的意思是有密码的一个单引号作为字符串中的两个单引号被视为1。

ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=compname\SQLEXPRESS;Database=DB;ID=username;Password="";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;"

+0

好点子。我已将其更改为单引号,但仍有一个错误,但不同: **错误:**初始化字符串的格式不符合OLE DB规范。 –

+0

我在_Properties ='Excel 12.0'_中发现另一个apostrphe失踪。填写完这些之后,我收到了“无法找到可安装的ISAM”。错误。任何线索? –

+0

这是一个连接字符串的网站。 https://www.connectionstrings.com/excel/ – Serenity