Jump to content

Accessing Linked Data


hcaelxxam

Recommended Posts

Hi everyone, I've been trying to figure this out on my own, but I can't seem to do it.

 

I have drawings where polylines are linked to a SQL Server database. I'm trying to write a command in autolisp that can pull that data. All the data I want to access you can view in the properties dialouge, but I have no clue how you would access that.

 

After doing quite a bit of research it seems like I'll have to figure out how to query the database based off of my keyvalue. I've tried using the stuff in caotest.lsp but none of those functions work for me for some reason.

 

All of this information below may be completely useless, but I figured the more I could tell ya'll about the situation the more likely you could help me.

 

Any help or links to documentation that will tell me what I need to do will be extemely appreciated. This is frustrating me pretty badly.

 

I am running AutoCAD Map 3D 2009 connecting to Microsoft SQL Server 2008 running on Windows Server 2008 R2.

 

I have the drawing connected to the link template. The datasource is "GIS"

and the LinkTemplate is "Links"

 

I'm connected to the database (successfully) on an ODBC Connection titled ODBC_1.

I have a .udl in the Data Links folder called Autocad.udl (which tests successfully)

 

I've tried to do this, but it just doesn't work.

(defun program()
 (vl-load-com)
 (setq cmd (vlax-create-object "ADODB.Command"))
 (setq ADOConnect (vlax-create-object "ADODB.Connection"))
 (vlax-put-property cmd "ActiveConnection" ADOConnect)
)

[b]Error:[/b]
; error: Automation Error. Requested operation requires an 
OLE DB Session object, which is not supported by the current provider.

I have no clue what that means so I've tried some other stuff using caotest.

(defun program()
 (vl-load-com)
 (setq acadObject (vlax-get-acad-object))
 (setq dbconnect (vla-getinterfaceobject (vlax-get-acad-object) "CAO.DbConnect.16"))
 (setq linktemplates (vlax-invoke-method dbconnect "GetLinkTemplates" acadObject))
 (setq linktemplate (vlax-invoke-method linktemplates "item" 0))
 (cmdShowLinkedRow_Click linkTemplate nil)
)

[b]Error:[/b]
Found 1 link(s) for the selected object(s) using link template, Links
; error: Automation Error. [Microsoft][ODBC SQL Server Driver]
[sql Server]Login failed for user 'hcaelxxam'.

But that doesn't work, so I tried something else:

(defun program()
 (setq commnd (vlax-create-object "CAO.DbConnect.16"))
 (setq con (vlax-invoke-method commnd "Connect" "GIS" "hcaelxxam" "XXXXXX" nil))
 (vlax-put-property cmd "ActiveConnection" con)
 (vlax-put-property cmd "ActiveConnection" con)
)

[b]Error:[/b]
; error: ActiveX Server returned an error: Invalid number of parameters

That error I get because con returns nil.

Link to comment
Share on other sites

The syntax of vlax-invoke-method does not seem to be correct.

 

Try using following format:

 

(vlax-invoke-method object-to-which-the-method-applies 'the-method-name-with-preceding-apostrophe-without-quotes parameter1 parameter2 ....)

 

Try using 'Connect instead of "connect" assuming that Connect is the method of Commd object.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...