Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx IO Discussions

Customize and extend the power of Alteryx with SDKs, APIs, custom tools, and more.

Alteryx Input Tool - System ODBC Connections?

trevo440
5 - Atom

Hi all,

 

Recently I designed a tool for searching through a database, which uses a pyodbc connection string that the user selects as a dropdown in the GUI for the program. Currently I have it set to a AlteryxDataItems.StringSelector, with labels and values that correspond to the connection eg. optionList : [{label:"SqlServer1" value:"DSN=SqlServer1"}]- where the value is the system ODBC.

 

I read the input through the config file on the tools run to test the connection:

 

self.DsnFieldName = Et.fromstring(str_xml).find('DsnField').text if 'DsnField' in str_xml else None
#try and except is elsewhere for handling SqlServer vs Splicemachine, etc.
cxn = pyodbc.connect(self.DsnFieldName) cursor = cxn.cursor() self.display_text_msg(f'Connection Passed with {self.DsnFieldName}')

 

I was wondering if there was a more dynamic method of reading the System ODBCs- such as what I assume the Input tool uses. I ask because our organization uses multiple VMs for our clients, and I would like to avoid instances where a connection is shown that doesn't exist on the particular VM. For reference, I've attached the .yxi with the hard-coded connections removed. Any help would be appreciated, thanks!

 

Not sure if posting the .yxi would be better for future reference or the best method for this- first time posting :)

 

Edit: line 85 of the html file might make this tool fail as an install- as the manager.bindDataItemToWidget is pointing to something that I removed. Really only posted the .yxi so that anyone who wishes to can unzip and extract to view the code. It would be pretty easy to edit the code for your own purposes, however, as all you need to do is update the optionList between lines 77-79 with your system ODBCs and change line 85 to the correct value.

0 REPLIES 0