The Goal
Write a program that reads .csv files and uploads them to a database. It must run on Windows 10 with no special installations necessary.
What I've Tried
I'm familiar with VBScript and ADO connections (I've actually already written and tested the file upload portion of the program). Now all I'm trying to do is read in the .csv file with ADO (see why to use ADO instead of split() here: https://msdn.microsoft.com/en-us/library/ms974559.aspx)
The article above creates the .csv connection using the Microsoft Jet Database Engine, which is not installed by default, so I tried with Microsoft Text Driver, as recommended by other sources.
The Problem
I'm encountering an error upon attempting a connection. The error says:
Microsoft OLE DB Provider for ODBC
Drivers: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
That error occurs whether run from 32-bit or 64-bit cmd (this is where I got the 32-bit process: How do I run a VBScript in 32-bit mode on a 64-bit machine?). The Microsoft Text Driver can be found in the 32-bit ODBC Drivers.
I do have a file called test.csv on my desktop and it contains the text "Cell1","Cell2","Cell3"
The Code
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adCmdText = &H0001
set WshShell = CreateObject("Wscript.shell")
strDesktop = WshShell.SpecialFolders("Desktop")
Set fileConn = CreateObject("ADODB.Connection")
Set fileRS = CreateObject("ADODB.Recordset")
strPathtoTextFile = strDesktop & "\"
' Wscript.Echo(strPathtoTextFile)
fileConn.ConnectionString = "Driver={Microsoft Text Driver (*.txt;*.csv)};DBQ=" & strPathtoTextFile & ";"
fileConn.Open
fileRS.Open "SELECT * FROM test.csv", _
fileConn, adOpenStatic, adLockOptimistic, adCmdText
The error occurs on the line fileConn.Open
. The code is a modified snippet from the Microsoft article above.
Any ideas why I'm getting this error?