How to create an ODBC connection with SAS?

I am writing a program that needs to access SAS data. I downloaded the ODBC drivers for SAS and installed them, but I need to be able to create ODBC connections on the fly, programmatically. The following code (in Python) seems to work:

import ctypes ODBC_ADD_DSN = 1 def add_dsn(name, driver, **kw): nul, attrib = chr(0), [] kw['DSN'] = name for attr, val in kw.iteritems(): attrib.append('%s=%s' % (attr, val)) return ctypes.windll.ODBCCP32.SQLConfigDataSource(0, ODBC_ADD_DSN, driver, nul.join(attrib)) == 1 print add_dsn('SAS Test', 'SAS', description = 'Testing SAS') 

But it pops up the SAS ODBC configuration dialog, sets the name of the data source and expects the user to enter information and reject the dialog. How can i avoid this?

+4
source share
3 answers

To get ODBC access to SAS data, you need to connect to a SAS session; you cannot directly access SAS data table files using ODBC SAS drivers.

See the SAS ODBC Driver Guide , section “What software do I need?”.

Your question does not indicate that you are trying to access SAS data through a working SAS product. The ODBC SAS Driver Guide should tell you how to configure a connection based on the SAS product with which you can connect.

+2
source

I know zilch about SAS, but the function used to connect to the database on the fly in ODBC is SQLDriverConnect . You do not need (or want) to add a DSN, you just need drivers.

0
source

I know this question is ancient, but it probably often appears so much that I will share the answer that I know. The easiest way to achieve what you are trying to do is to create what is called a "DSN-Less Connection".

In short, you create a connection string that is used when opening a connection that identifies the driver and includes all the parameters that you usually fill in when creating the DSN for this driver.

This method has existed for a very long time - I used it in 2001, and it was older than this.

The following is an example of a DSN-Less connection string sequence for accessing SAS data through ODBC:

Using Server ID Provider=sas.ShareProvider;Data Source=shr1;

SAS / SHARE Using server identifier and node (network name) Provider = sas.ShareProvider; Data Source = shr1; Location = lambchop.unx.sas.com;

SAS / SHARE Indication of user and password Provider=sas.ShareProvider;Data Source=shr1;Location=lambchop.unx.sas.com; User ID=myUsername;Password=myPassword; Provider=sas.ShareProvider;Data Source=shr1;Location=lambchop.unx.sas.com; User ID=myUsername;Password=myPassword;

SAS / SHARE Server requires password Provider=sas.ShareProvider;Data Source=shr1;Location=lambchop.unx.sas.com; User ID=myUsername;Password=myPassword; SAS Server Access Password=myServerPassword; Provider=sas.ShareProvider;Data Source=shr1;Location=lambchop.unx.sas.com; User ID=myUsername;Password=myPassword; SAS Server Access Password=myServerPassword;

This is from: https://www.connectionstrings.com/sas-share/

The SAS support page discusses this more ... I found it here: http://docslide.us/documents/opening-an-ado-connection-object.html

0
source

Source: https://habr.com/ru/post/1302766/


All Articles