How to connect to DAO library through visual lisp functions

How to connect to DAO library through visual lisp functions

ivanstarr3
Contributor Contributor
1,052 Views
6 Replies
Message 1 of 7

How to connect to DAO library through visual lisp functions

ivanstarr3
Contributor
Contributor

I did search under the provided mechanism and on the web in gnereal for this, you would think it would be more in demand, but I found nothing.

 

I'm simply trying to get access to the regular, original MS database access object library DAO, that's inside every copy of MS Access, in my case it's in a .dll called 

 

C:\\Program Files\\Common Files\\microsoft shared\\OFFICE16\\ACEDAO.DLL.

 

Now, when I 

(vlax-import-type-library :tlb-filename "C:\\Program Files\\Common Files\\microsoft shared\\OFFICE16\\ACEDAO.DLL")

it askes me if I want to enter a break loop because there's an "Assignment to protected symbol (XXXX)", it asks me several times, about symbols like "Append Chunk", "BeginTrans", "Cancel" (which are probably all in DAO), to which I respond NO to all, then the function returns T.  

 

But then 

(setq DBEngine (vlax-create-object "DAO.DBEngine"))

returns nil.

 

why doesn't (setq DBEngine (vlax-create-object "DAO.DBEngine")) work? The
question is, how does one create a "DBEngine" object from the "DAO"
library, if not (setq DBEngine (vlax-create-object "DAO.DBEngine"))?

 

Anyone have any idea what to do?  This library is unbelieveably useful, surely these 2 unbuhlieveable products play nice with each other, right?

 

Thanks,

 

Ivan

 

PS - This was posted on the AutoCAD customization forum last week with no resolution so I thought I'd put it here and see if anyone knows on this forum too before I bother ADN support, wherever it is

0 Likes
1,053 Views
6 Replies
Replies (6)
Message 2 of 7

O_Eckmann
Mentor
Mentor
0 Likes
Message 3 of 7

ivanstarr3
Contributor
Contributor
Yes I have seen this post, but it won't do it. ADO sucks, I greatly prefer
DAO.

Ivan
0 Likes
Message 4 of 7

norman.yuan
Mentor
Mentor

This forum is for AutoCAD .NET API. You might get better responds from Lisp forum.

 

With that said, DAO or ADO, whichever you think sucks, may not matter, because the real issue could be that you must use 64-bit MS Access DB Engine to match your 64-bit AutoCAD (you are not using 32-bit AutoCAD, are you?). VLisp's (vlax ....) functions use "in-process" COM API behind of the scene, so the data access engine must also be 64-bit when AutoCAD is 64-bit.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 7

ivanstarr3
Contributor
Contributor
Norman, thanks for replying! How you doin'?

I posted thei qn there first but when it went unsolved I posted it here in
.NET jic there's some brilliant dude here like you to help me out. Didn't
that work out nice?

Anyway, yeah that's right, it's gotta be 64-bit too, BUT IT IS! because
it's THE database engine of ms Access and it comes with Access, but as far
as I know, instancing Access.Application does not allow you access to
DBEngine. DBEngine is the Top DAO object and it resides in ACEDAO.DLL, and
vlax-importing it, as in

(vlax-import-type-library
:tlb-filename
"C:\\Program Files\\Common Files\\microsoft
shared\\OFFICE16\\ACEDAO.DLL"
:methods-prefix
"daom-"
:properties-prefix
"daop-"
:constants-prefix
"daoc-"
)
returns T, but then
(setq DBEngine (vlax-get-or-create-object "DAO.DBEngine"))
returns nil.

So how do you get an instance of DBEngine, which is the top of the DAO
hierarchy, that's the question here, ONLY.

If you can figure this one out, you're a dandy!

Ivan
0 Likes
Message 6 of 7

norman.yuan
Mentor
Mentor

So, you are saying that you do have the Access DB engine 64-bit installed (because of MS Access 64-bit, or MS Office suite 64-bit that including MS Access, installation)? If so, maybe, this discussion would be of help (pay attention to "Click-To-Run" mentioned in the answers):

 

https://stackoverflow.com/questions/46462678/acedao-dbengine-available-from-access-but-not-from-net 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 7

ivanstarr3
Contributor
Contributor
Norman,

Hmmm very interesting as it's confirming behavior I just noticed.... After
some woman suggested instantiating MSAccess thinking that's what I really
wanted, at first I wrongly assumed that DBEngine wouldn't be accessible,
but a few days later I thought about how stupid that would be and how
complete the object model is, so I looked at the Access object model and
there it was, right off the application - Application.DBEngine! So I
instantiated it and then the DBEngine in VLisp with the following code -


(setq MSAccess (vlax-create-object "Access.Application"))
(setq DBEngine (vlax-get-property MSAccess 'DBEngine))
(setq Workspace (vlax-invoke DBEngine 'CreateWorkspace "AccessWorkspace"
"Admin" "" '""))
(setq DB (vlax-invoke Workspace 'OpenDatabase "C:\\BA\\BA.mdb"))
(setq rstEmployeesRecordset (vlax-invoke DB 'OpenRecordset "SELECT Name
FROM [Employees];"))
(setq nNumRecords (vlax-get-property rstEmployeesRecordset 'RecordCount))
(vlax-invoke rstEmployeesRecordset 'MoveLast)
(vlax-invoke rstEmployeesRecordset 'MoveFirst)
(setq nNumRecords (vlax-get-property rstEmployeesRecordset 'RecordCount))
(setq EmployeeRecords (vlax-safearray->list (vlax-invoke
rstEmployeesRecordset 'GetRows nNumRecords)))


And IT WORKED (right up to the 'GetRows invocation, but thats another
error)! BUT I NEVER was able to access the DBEngine object outside of
Access.Application! WOW! just like what that article talks about. I
still however would love to know from a horse's mouth what the official
disposition of all this is, ie how do you get a DBEngine object without,
and outside of, Access?
0 Likes