我跑了好几次。大约一年前,我开始使用sql脚本,一切都很好,但现在我遇到了一个错误,上面说:
OperationalError: ('08001', '[08001] [Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [2]. (2) (SQLDriverConnect); [08001] [Microsoft][SQL Server Native Client 11.0]Login timeout expired (0); [08001] [Microsoft][SQL Server Native Client 11.0]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online. (2)')
下面是我正在测试的两个示例脚本。
import sqlalchemy
import pyodbc
engine = pyodbc.connect(driver='{SQL Server Native Client 11.0}', host='CEDUMII6', database='TestDB', trusted_connection='yes')
df.to_sql('healthcare', engine, if_exists='replace', index=True, chunksize=100000)
和
import sqlalchemy
import pyodbc
engine = "mssql+pyodbc://CEDUMII6/TestDB?driver=SQL Server Native Client 11.0?trusted_connection=yes"
df.to_sql('healthcare', con=engine, if_exists='replace', index=True, chunksize=100000)
和
import sqlalchemy
import pyodbc
server = 'CEDUMII6'
database = 'TestDB'
con = pyodbc.connect('DRIVER={ODBC Driver 11 for SQL Server};SERVER=' + server + ';DATABASE=' + database +';Trusted_Connection=yes')
df.to_sql('healthcare', con=engine, if_exists='append', index=True, chunksize=100000)
我的防火墙关闭了!我肯定错过了一些简单的东西,但我不知道是什么。知道这里怎么了吗?