1

I wanted to execute the below SQL Script on local SQL Express server:

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

Query run from SQL Express works fine. But when I try to run it from 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")

it displays following error:

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

2 Answers 2

1

Did you mean to have a single quote for password as two quotes in a string are treated as 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;"

Sign up to request clarification or add additional context in comments.

5 Comments

Good point. I have changed that to single quote but there is still an error, different however: Error: Format of the initialization string does not conform to the OLE DB specification.
And I have found another apostrphe missing in Properties='Excel 12.0'. After filling this in I am getting the "Could not find installable ISAM." error. Any clues?
Here is a web site of connection strings. connectionstrings.com/excel
The connection string is correct. But now I get error saying: "ActiveX component can't create object: OLEDB.Connection"
Use the Query Helper in Excel. Alt + D, D, N, then double click Excel, browse, choose options, then chosse to edit query at end of wizard. Then in Editor File Save. This text file will have a connection string and sql string in it.
1

Correct connection string:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.