I am trying to execute a very simple example of using SQLOLEBD to retrieve records from a CSV file using VBScript.
I am getting the error:
Line: 4
Char: 1
Error: Invalid connection string attribute”
Code: 80004005
Source: Microsoft OLD DB Provider for SQL Server
Can somebody please straighten me out?
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
objConnection.Open "Provider=SQLOLEDB; Data Source= C:\Users\public\; Extended Properties=""text;HDR=YES;FMT=Delimited"""
objRecordset.Open "SELECT * FROM employees.csv, objConnection, adOpenStatic, adLockOptimistic, adCmdText"
Do Until objRecordset.EOF
Wscript.Echo "name: " & objRecordset.Fields.Item("Name")
objRecordset.MoveNext
Loop
wscript.echo "Finished"
employees.csv
id,name,grade
1,”Ezequiel, Justin”,1
2,Charlie Sheen,4
3,”Name, Your”,8
4,Another Guy,16
The immediate cause of your error is using the wrong OLE DB provider (your Jet provider error might be a 32-bit vs 64-bit issue), but it appears that your real goal is to join data in a text file with data in a table.
Two fairly simple options are a) load the file into a SQL Server table using one of the various bulk loading methods and then join the tables as usual, or b) join the table on the file directly using OPENROWSET(). If you’ll do this a lot, or if you have a lot of data, the first approach is probably better because you can leverage the database engine for indexing and better join performance.
You could use SSIS for this too, but it’s probably overkill in this scenario.
And mentioning your SQL Server version and other specific details is always useful.