简体   繁体   English

无法使用来自另一个域的 pyodbc 连接到 SQL 服务器

[英]Cannot connect to SQL Server using pyodbc from another domain

I'm trying to connect to it from another domain with this code below but I'm getting an error like this我正在尝试使用下面的代码从另一个域连接到它,但我收到这样的错误

InterfaceError: (pyodbc.InterfaceError) ('28000', '[28000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication. (18452) (SQLDriverConnect); [28000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Login failed. The login is from an untrusted domain and cannot be used with Integrated authentication. (18452)') (Background on this error at: http://sqlalche.me/e/13/rvf5) InterfaceError: (pyodbc.InterfaceError) ('28000', '[28000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]登录失败。登录来自不受信任的域,不能用于集成身份验证。( 18452) (SQLDriverConnect); [28000] [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]登录失败。登录来自不受信任的域,不能用于集成身份验证。(18452)') (背景此错误位于:http://sqlalche.me/e/13/rvf5)

This is my code that I'm using:这是我正在使用的代码:

import pyodbc
from sqlalchemy import create_engine

server = 'shul'

database = 'db_pre'

uid = 'pre'
pwd = 'pr@20si'

engine = create_engine('mssql+pyodbc://' + server + '/' + database + '/' + uid + '/' + pwd + '?trusted_connection=no&driver=ODBC+Driver+13+for+SQL+Server')

#engine = create_engine('mysql://root:@localhost/daming') # enter your password and database names here

col_names = ["month", "price", "change"]
df = pd.read_csv("kcl.csv",sep=',',quotechar='\'',encoding='utf8', names=col_names,skiprows = 1) # Replace Excel_file_name with your excel sheet name
df.to_sql('kcl',con=engine,index=False,if_exists='replace') # Replace Table_name with your sql table name

In SQL Server Management Studio I used SQL Server authentication instead of Windows Authentication.在 SQL 服务器管理工作室中,我使用了 SQL 服务器身份验证,而不是 Windows 身份验证。

Please help me.请帮我。 Thank you in advance.先感谢您。

You can study this link:你可以研究这个链接:

https://docs.djangoproject.com/en/2.2/ref/settings/#databases https://docs.djangoproject.com/en/2.2/ref/settings/#databases

Set similar config:设置类似的配置:

   DATABASES = {
        "default": {
            "ENGINE": "sql_server.pyodbc",
            "NAME": env("database_name"),
            "USER": env("database_user"),
            "PASSWORD": env("database_password"),
            "HOST": env("database_host"),
            "PORT": env("database_port"),
            "OPTIONS": {
                "driver": "ODBC Driver 17 for SQL Server",
                "unicode_results": True,
            },
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM