Question

Here I have a batch/jscript file that creates odbc dns (Microsoft Text Driver (*.txt; *.csv)) , connect to it but when I try to execute a query I get error . Here's the .bat file that can directly be ran and tested:

@if (@X)==(@Y) @end /* JScript comment
@echo off

rd /s /q C:\dbtest
md C:\dbtest
rem create a new "database"
(
echo "col1","col2"
echo "1","2"
) >>C:\dbtest\test.txt
odbcconf configdsn "Microsoft Text Driver (*.txt; *.csv)" "DSN=testdns1|description=test_dns_1|defaultdir=C:\dbtest"
 cscript //E:JScript //nologo "%~f0"

exit /b 0

*/
var rs = new ActiveXObject("ADODB.Recordset");
var comm=new ActiveXObject("ADODB.Command");
var conn = new ActiveXObject("ADODB.Connection");
conn.ConnectionString="testdns1";
// read write
conn.Mode=3

conn.Open;
conn.Execute("Select  * FROM test");
conn.Close();

for 64bit machines:

@if (@X)==(@Y) @end /* JScript comment
@echo off
setlocal
path %windir%\sysWOW64\
rd /s /q C:\dbtest
md C:\dbtest
rem create a new "database"
(
echo "col1","col2"
echo "1","2"
) >>C:\dbtest\test.txt
odbcconf configdsn "Microsoft Text Driver (*.txt; *.csv)" "DSN=testdns1|description=test_dns_1|defaultdir=C:\dbtest"
 cscript //E:JScript //nologo "%~f0"
endlocal
exit /b 0

*/


var rs = new ActiveXObject("ADODB.Recordset");
var comm=new ActiveXObject("ADODB.Command");
var conn = new ActiveXObject("ADODB.Connection");
conn.ConnectionString="testdns1";
// read write
conn.Mode=3

conn.Open;
conn.Execute("Select  * FROM test");
conn.Close();

but at conn.Execute("Select * FROM test"); I'm receiving following error:

 Microsoft OLE
DB Provider for ODBC Drivers: [Microsoft][ODBC Text Driver] The Microsoft Jet da
tabase engine cannot open the file '(unknown)'.  It is already opened exclusivel
y by another user, or you need permission to view its data.

The activex objects are created with jscript but is identical to vbscript (I've even used vbscript examples as reference).

Any idea what could cause this error?As the file is just created from the same user and nobody use it at the same time

Was it helpful?

Solution

The name of yout table is test.txt. So change

conn.Execute("Select  * FROM test");

to

conn.Execute("Select  * FROM [test.txt]");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top