Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

Unable to perform inner join of two SQL tables from python, getting communication link error/ connection write error

I am deploying my model results in the database. I have read the data from SQL using pyodbc connection. Ran ML model in python and have predicted results 'ColA, ColB, ColC'. The main table already has these columns with values as NULL.

Main table:

|Number| ColA   | ColB   | ColC |
|:---- |:------:| :-----:|-----:|
| 123  |  NULL  | NULL   |NULL  |
| 456  | NULL   | NUL    |NULL  |

After model run, I have saved the predicted values in temp table.

Temp table:

|Number| ColA   | ColB   | ColC  |
|:---- |:------:| :-----:|-----: |
| 123  | India  |2-Jan-21|10:00AM|
| 456  | USA    |2-Jan-21|12:00AM|

Now I need to update the values of 'ColA, ColB, ColC' in Main table based on Number.

I tried below queries:

statement = '''
UPDATE Maintable
SET
     ColA= u.ColA,  
     ColB= u.ColB,
     ColC= u.ColC,
FROM Maintable AS t
INNER JOIN Temptable u ON t.Number=u.Number;
'''

This gives below errors:

OperationalError: ('08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]Communication link failure (0) (SQLExecDirectW)')

Sometimes this error:

Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][Shared Memory]ConnectionWrite (send()). (10054) (SQLExecDirectW); [01000] [Microsoft][ODBC SQL Server Driver][Shared Memory]General network error. Check your network documentation. (11)')

And if it runs successfully without errors, when I do select * from Maintable, the job runs for long and unable to view the table. Have to forcefully kill the job.

How to overcome this error? is there any other way to update the SQL data from python?

question from:https://stackoverflow.com/questions/66059758/unable-to-perform-inner-join-of-two-sql-tables-from-python-getting-communicatio

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...