WPerciful Posted February 12, 2014 Posted February 12, 2014 LISP to query MS SQL Server Database return results as list of strings. (defun getMySqlData ( Name / ) (setq pm Name SQLCon "Server=OurServer;Database=engineering;Trusted_Connection=True" SQLStatement1 "USE enginering SELECT ID FROM Projects WHERE ProjectName = pm" SQLStatement2 "USE enginering SELECT * FROM LineList WHERE ProjectID = ResultsID" ) ; I'm trying to use SQLStatement1 to get the project ID. ; So that I can use it to run this SQLStatement2 ; Then return the results of the above as a list of strings. ) Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 In this example I bring a recordset the str_FIELD_INTABLE variable receives the 0 position of the query. The first field. (vl-load-com) (if adoConnect (if (= 1 (vlax-get-property ADOConnect "State")) (vlax-invoke-method ADOConnect "Close") ) ) (setq adoconnect nil) (setq ADOConnect (vlax-create-object "ADODB.Connection")) (setq currConnectionString " ENTER A STRING CONNECTION ") (vlax-put-property ADOConnect "ConnectionString" currConnectionString) (vlax-invoke-method ADOConnect "Open" currConnectionString "" "" -1) (setq cmd2 (vlax-create-object "ADODB.command")) (vlax-put-property cmd2 "ActiveConnection" ADOConnect) (vlax-put-property cmd2 "CommandTimeout" 30) (vlax-put-property cmd2 "CommandText" (strcat "select FIELD_INTABLE from TABLE")) (setq rs2 nil) (setq rs2 (vlax-create-object "ADODB.Recordset")) (vlax-invoke-method rs2 "OPEN" cmd2 nil nil nil nil) (setq campos (vlax-get-property rs2 "Fields")) (while (not (equal :vlax-true (vlax-get-property rs2 "EOF"))) (setq item11 (vlax-get-property campos "item" 0)) (setq str_FIELD_INTABLE (vlax-variant-value (vlax-get-property item11 "value"))) ;;;;; -------------------------- ;;;;; -------------------------- ;;;;; in this point use the field result str_FIELD_INTABLE , ou create more field results( "item" 1 , 2 , 3 ...) ;;;;; -------------------------- ;;;;; -------------------------- (vlax-invoke-method rs2 "movenext") ) (setq rs2 nil) (setq cmd2 nil) (if adoConnect (if (= 1 (vlax-get-property ADOConnect "State")) (vlax-invoke-method ADOConnect "Close") ) ) (setq adoconnect nil) Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 LISP to query MS SQL Server Database return results as list of strings. (defun getMySqlData ( Name / ) (setq pm Name SQLCon "Server=OurServer;Database=engineering;Trusted_Connection=True" SQLStatement1 "USE enginering SELECT ID FROM Projects WHERE ProjectName = pm" SQLStatement2 "USE enginering SELECT * FROM LineList WHERE ProjectID = ResultsID" ) ; I'm trying to use SQLStatement1 to get the project ID. ; So that I can use it to run this SQLStatement2 ; Then return the results of the above as a list of strings. ) I modded it to this: (progn (vl-load-com) (if adoConnect (if (= 1 (vlax-get-property ADOConnect "State")) (vlax-invoke-method ADOConnect "Close") ) ) (setq adoconnect nil) (setq ADOConnect (vlax-create-object "ADODB.Connection")) (setq currConnectionString "Server=OurServer;Database=engineering;Trusted_Connection=True") (vlax-put-property ADOConnect "ConnectionString" currConnectionString) (vlax-invoke-method ADOConnect "Open" currConnectionString "" "" -1) (setq cmd2 (vlax-create-object "ADODB.command")) (vlax-put-property cmd2 "ActiveConnection" ADOConnect) (vlax-put-property cmd2 "CommandTimeout" 30) (vlax-put-property cmd2 "CommandText" (strcat "USE enginering SELECT * FROM LineList")) (setq rs2 nil) (setq rs2 (vlax-create-object "ADODB.Recordset")) (vlax-invoke-method rs2 "OPEN" cmd2 nil nil nil nil) (setq campos (vlax-get-property rs2 "Fields")) (while (not (equal :vlax-true (vlax-get-property rs2 "EOF"))) (setq item11 (vlax-get-property campos "item" 0)) (setq str_FIELD_INTABLE (vlax-variant-value (vlax-get-property item11 "value"))) ;;;;; -------------------------- ;;;;; -------------------------- ;;;;; in this point use the field result str_FIELD_INTABLE , ou create more field results! ;;;;; -------------------------- ;;;;; -------------------------- (vlax-invoke-method rs2 "movenext") ) (setq rs2 nil) (setq cmd2 nil) (if adoConnect (if (= 1 (vlax-get-property ADOConnect "State")) (vlax-invoke-method ADOConnect "Close") ) ) (setq adoconnect nil) ) I got this error: ; error: Automation Error. [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 No, I do not know what that is. Where can I go to get it? Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 See my string Provider=SQLOLEDB;Server=MYSERVER;Database=MYDATAB ASE;Uid=USER;Pwd=PASSWORD; Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 I need :version of your windows and version of your sqlserver. Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 I am running Windows 7 here. Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 you need download and execute this file SQLNCLI.msi however need to know the version of your sqlserver. Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 The Server management studio I used to make the database is: Microsoft SQL Server Management Studio 11.0.3128.0 Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 Windows 7 32 or 64 bits ? LINK 32 http://go.microsoft.com/fwlink/?LinkID=239647&clcid=0x416 LINK 64 http://go.microsoft.com/fwlink/?LinkID=239648&clcid=0x416 Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 I'm running Windows 7 64-bit Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 Download and exec this LINK 64 http://go.microsoft.com/fwlink/?Link...48&clcid=0x416 Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 Awesome! But it's not in English, do you have a link for one in English? Or does it not matter? Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 Insert in your stringConnection this (Provider=SQLOLEDB;) Provider=SQLOLEDB;Server=OurServer;Database=engineering;Trusted_Connection=True Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 Try this link X64 ENGLISH http://go.microsoft.com/fwlink/?LinkID=239664&clcid=0x409 Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 Awesome, thank you very much. I am installing it now. Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 after installing, restart the computer and test the routine again in autocad. Insert in your stringConnection this -----Provider=SQLOLEDB------ Provider=SQLOLEDB;Server=OurServer;Database=engine ering;Trusted_Connection=True check ( server , database , and type of login in database ) Quote
WPerciful Posted February 12, 2014 Author Posted February 12, 2014 I get an error with this line: (vlax-put-property cmd2 "ActiveConnection" ADOConnect) The error: ; error: Automation Error. Invalid authorization specification The modded code I'm using: (progn (vl-load-com) (if adoConnect (if (= 1 (vlax-get-property ADOConnect "State")) (vlax-invoke-method ADOConnect "Close") ) ) (setq adoconnect nil) (setq ADOConnect (vlax-create-object "ADODB.Connection")) (setq currConnectionString "Provider=SQLOLEDB;Server=OurServer;Database=engineering;Trusted_Connection=True") (vlax-put-property ADOConnect "ConnectionString" currConnectionString) (vlax-invoke-method ADOConnect "Open" currConnectionString "" "" -1) (setq cmd2 (vlax-create-object "ADODB.command")) (vlax-put-property cmd2 "ActiveConnection" ADOConnect) (vlax-put-property cmd2 "CommandTimeout" 30) (vlax-put-property cmd2 "CommandText" (strcat "USE enginering SELECT * FROM LineList")) (setq rs2 nil) (setq rs2 (vlax-create-object "ADODB.Recordset")) (vlax-invoke-method rs2 "OPEN" cmd2 nil nil nil nil) (setq campos (vlax-get-property rs2 "Fields")) (while (not (equal :vlax-true (vlax-get-property rs2 "EOF"))) (setq item11 (vlax-get-property campos "item" 0)) (setq str_FIELD_INTABLE (vlax-variant-value (vlax-get-property item11 "value"))) ;;;;; -------------------------- ;;;;; -------------------------- ;;;;; in this point use the field result str_FIELD_INTABLE , ou create more field results! ;;;;; -------------------------- ;;;;; -------------------------- (vlax-invoke-method rs2 "movenext") ) (setq rs2 nil) (setq cmd2 nil) (if adoConnect (if (= 1 (vlax-get-property ADOConnect "State")) (vlax-invoke-method ADOConnect "Close") ) ) (setq adoconnect nil) ) Quote
rodrigo_sjc_sp Posted February 12, 2014 Posted February 12, 2014 (edited) Try change the provider Provider=SQLNCLI; The ideal would be to create a username and password in sqlserver with full privileges and make a test using the same. Other way : Try to update ( Microsoft® SQL Server® 2012 Service Pack 1 (SP1) ) http://www.microsoft.com/en-us/download/details.aspx?id=35575 I find this text http://support.microsoft.com/kb/2652582/en-us I believe the problem will be solved with a registered user in the database, with every privilege. You have to generate a user? Edited February 12, 2014 by rodrigo_sjc_sp Quote
Recommended Posts
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.