I'm connecting to two databases the first one uses 'SQL Server Authentication' the second which is the issue uses 'Active Directory Universal Authentication'.
我正在连接两个数据库,第一个使用“SQL Server身份验证”,第二个是问题,使用“Active Directory通用身份验证”。
Running this on Win 7, python 2.7.12, pyodbc v4.0.17, Microsoft Online Services Sign-in Assistant is installed and I normally access the database from MSSMS 2016.
在Win 7,python 2.7.12,pyodbc v4.0.17上运行此命令,安装了Microsoft Online Services登录助手,我通常从MSSMS 2016访问数据库。
For the first database I use the following, which works:
对于第一个数据库,我使用以下工作:
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=ourDatabase.database.windows.net;PORT=1433;DATABASE=ourDataBaseName;UID=USERID;PWD=PASSWORD')
The second database I've tried all of these, which don't work:
第二个数据库我已经尝试了所有这些,但不起作用:
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=.\ourDatabase.database.windows.net;DATABASE=ourDataBaseName;UID=user@companydomain.com;PWD=MyPass;Trusted_Connection=yes')
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=ourDatabase.database.windows.net;DATABASE=ourDataBaseName;UID=user@companydomain.com;PWD=MyPass;Trusted_Connection=yes')
cnxn = pyodbc.connect('DRIVER={SQL Server};SERVER=ourDatabase.database.windows.net;DATABASE=ourDataBaseName;UID=user;PWD=MyPass;Trusted_Connection=yes')
cnxn = pyodbc.connect('DRIVER={ODBC Driver 13 for SQL Server};SERVER=.\ourDatabase.database.windows.net;DATABASE=ourDataBaseName;UID=user@companydomain.com;PWD=MyPass;Trusted_Connection=yes')
What am I missing here?
我在这里想念的是什么?
1 个解决方案
#1
4
Have you tried this:
你试过这个:
cnxn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER=YOURSERVER;DATABASE=YOURDATABASE;Trusted_Connection=yes')
Be sure to use a driver that is available in the computer you're using. To check which you can use:
请务必使用您正在使用的计算机中可用的驱动程序。要检查您可以使用哪个:
pyodbc.drivers()
Also, chances are that if you're on a work computer, you already have the obdc administrator loaded with a connection pre-configured. To check you can search on the windows menu for 'odbc administration' if you open up and there's the connection you want, you can use it and then just call it:
此外,如果您在工作计算机上,则可能已经为obdc管理员加载了预先配置的连接。要检查您是否可以在Windows菜单上搜索“odbc administration”,如果您打开并且有所需的连接,您可以使用它然后只需调用它:
cnxn = pyodbc.connect('DSN=YOURCONNECTIONNAME')
#1
4
Have you tried this:
你试过这个:
cnxn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER=YOURSERVER;DATABASE=YOURDATABASE;Trusted_Connection=yes')
Be sure to use a driver that is available in the computer you're using. To check which you can use:
请务必使用您正在使用的计算机中可用的驱动程序。要检查您可以使用哪个:
pyodbc.drivers()
Also, chances are that if you're on a work computer, you already have the obdc administrator loaded with a connection pre-configured. To check you can search on the windows menu for 'odbc administration' if you open up and there's the connection you want, you can use it and then just call it:
此外,如果您在工作计算机上,则可能已经为obdc管理员加载了预先配置的连接。要检查您是否可以在Windows菜单上搜索“odbc administration”,如果您打开并且有所需的连接,您可以使用它然后只需调用它:
cnxn = pyodbc.connect('DSN=YOURCONNECTIONNAME')