如何创建与SAS的ODBC连接? [英] How can I create an ODBC connection to SAS?

查看:417
本文介绍了如何创建与SAS的ODBC连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个需要访问SAS数据的程序.我已经下载了SAS的ODBC驱动程序并安装了它们,但是我需要能够以编程方式快速创建ODBC连接.以下代码(在Python中)似乎应该可以正常工作:

I'm writing a program that needs to access SAS data. I've 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 like it should 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')

但是它将弹出SAS ODBC配置对话框,设置数据源名称,并等待用户输入信息并关闭该对话框.我该如何避免呢?

But it pops up the SAS ODBC configuration dialog, sets the datasource name, and waits for the user to enter the information and dismiss the dialog. How can I avoid that?

推荐答案

为了获得对SAS数据的ODBC访问,您需要连接到某种正在运行的SAS会话.您不能直接使用SAS ODBC驱动程序访问SAS数据表文件.

In order to get ODBC access to SAS data, you need to connect to a running SAS session of some kind; you can't access SAS data table files directly with the SAS ODBC drivers.

请参见 SAS ODBC驱动程序指南,我需要什么软件?"部分.

See the SAS ODBC drivers guide, section "What Software Do I Need?".

您的问题并不表示您正在尝试通过运行中的SAS产品访问SAS数据. SAS ODBC驱动程序指南应告诉您如何基于将通过其建立连接的SAS产品来建立连接.

Your question doesn't state that you are trying to access SAS data through a running SAS product. The SAS ODBC drivers guide should tell you how to set up the connection based on the SAS product you will make the connection through.

这篇关于如何创建与SAS的ODBC连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆