views:

230

answers:

6

I'm having a problem with Jet throwing error 3011 when I try to use it to open a file with 2 "extensions" ("filename.tst.csv").

Run-time error '3011'

The Microsoft Jet database engine could not find the object 'filename.tst.csv'. Make sure the object exists and that you spell its name and the path name correctly.

Where the code looks like this:

Dim db as Database, rs as Recordset
Set db = OpenDatabase("SELECT TOP 1 * FROM [" & fileName & "];")
Set rs = db.OpenRecordset("SELECT TOP 1 * FROM [" & fileName & "];")

I've tracked down the problem to be the second extension (or apparent extension) ".tst" but I'm not sure why the error is occurring and I haven't been able to find an answer through Google or through here - but I figure someone might have some insight as to the limitations.

This is using DAO 3.6 in VB6.

+2  A: 

It's a bit hackey, but you could programatically rename the file before opening it to a more friendly extension. Just keep the old extension around so you can set it back when you are done.

Ryan Michela
Yea that's probably the solution I'll go with if I can't find a better one - it's just for import (copying into an internal format) so I'd just copy it to a temp folder with a better file name.
Corazu
+1  A: 

This isn't exactly the situation you're talking about, but in reading this, in the CAUSE section, the information about some drivers not supporting long filenames looks like it would apply, since this is not in an 8.3 format.

http://social.technet.microsoft.com/Search/en-US?query=3011&ac=8

So, you'd need to rename the file OR use another method to load the data (such as using a StreamReader). Personally, I'd rename the file. It'd be much easier.

David Stratton
Technically not the solution I was looking for but seems to provide a reason as to why this is failing, or at least the best hint I could find as to why it fails.
Corazu
A: 

You need to either create a schema.ini file for your import file, or add the extension to the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\4.0\Engines\Text\Format registry key so ADO knows how to parse the file. There is a detailed explanation at http://msdn.microsoft.com/en-us/library/ms974559.aspx

Beaner
Schema.ini is already created - that's not the problem. Also I'm not using ADO I'm using DAO.
Corazu
Sorry, I missed the DAO. I jumped in because I had this issue a few years ago importing a CSV file with an oddball extension to a VFP table.
Beaner
+1  A: 

Why not just use the short file name instead? It won't contain more than one period. Just drop in the CFileInfo class from this offering from Karl E Peterson's excellent site (it has a wrapper method for the GetShortPathName API call).

I suppose the volume might not support short file names (it's optional).

MarkJ
A: 

I'm not certain about this because I haven't used DAO much since it became obsolete in VB6. I know that Jet's rules can be very different going between the OLE DB Provider, ODBC Driver, and DAO.

Have you tried replacing the "." characters in those file names by "#" characters? Or maybe just the last one? Just in your SQL statement text.

Bob Riemersma
I too thought of this but when I tried it didn't seem to work :(
onedaywhen
Yes I did try this, it comes out to the same error though.
Corazu
A: 

According to me, your second line of code cannot return anything!

Set db = OpenDatabase("SELECT TOP 1 * FROM [" & fileName & "];")

You cannot open a database with a SELECT instruction! Your code shouls look like

Set db = DBEngine.Workspaces(0).OpenDatabase(filenamne)
Philippe Grondier