問題描述
我正在編寫一個(gè)需要訪問 SAS 數(shù)據(jù)的程序.我已經(jīng)下載了 SAS 的 ODBC 驅(qū)動(dòng)程序并安裝了它們,但我需要能夠以編程方式即時(shí)創(chuàng)建 ODBC 連接.以下代碼(在 Python 中)似乎應(yīng)該可以工作:
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')
但它會(huì)彈出SAS ODBC配置對(duì)話框,設(shè)置數(shù)據(jù)源名稱,并等待用戶輸入信息并關(guān)閉對(duì)話框.我怎樣才能避免這種情況?
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?
推薦答案
為了獲得對(duì) SAS 數(shù)據(jù)的 ODBC 訪問,您需要連接到某種正在運(yùn)行的 SAS 會(huì)話;您無法使用 SAS ODBC 驅(qū)動(dòng)程序直接訪問 SAS 數(shù)據(jù)表文件.
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.
請(qǐng)參閱 SAS ODBC 驅(qū)動(dòng)程序指南,我需要什么軟件?"部分.
See the SAS ODBC drivers guide, section "What Software Do I Need?".
您的問題并未說明您正在嘗試通過正在運(yùn)行的 SAS 產(chǎn)品訪問 SAS 數(shù)據(jù).SAS ODBC 驅(qū)動(dòng)程序指南應(yīng)告訴您如何根據(jù)您將通過的 SAS 產(chǎn)品建立連接.
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.
這篇關(guān)于如何創(chuàng)建與 SAS 的 ODBC 連接?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!