Как изменить данные в файле .bak, резервную копию которого имеется в MSSQL, для вставки формата данных? ⇐ Python
Как изменить данные в файле .bak, резервную копию которого имеется в MSSQL, для вставки формата данных?
With help from ChatGPT, I received the code below and am checking it, but I don't know why the error occurs. Please help me
import pyodbc conn_str = 'DRIVER={SQL Server};Server=myserver;Database=mydatabase;Trusted_Connection=True' # create connection conn = pyodbc.connect(conn_str) # backup path backup_file_path = 'D:\\Test.bak' cursor = conn.cursor() cursor.execute("CREATE TABLE #TempTable (D VARBINARY(MAX))") with open(backup_file_path, 'rb') as f: backup_data = f.read() cursor.execute("INSERT INTO #TempTable (D) VALUES (?)", backup_data) select_query = "SELECT data FROM #TempTable" for row in cursor.execute(select_query): backup_data = row[0].decode('utf-8') table_data = backup_data.split("INSERT INTO ") for table_insert in table_data[1:]: table_name = table_insert.split()[0] values_start_index = table_insert.find("VALUES") + len("VALUES") table_values = table_insert[values_start_index:].strip().strip(";") insert_script = f"INSERT INTO {table_name} {table_values};" print(insert_script) cursor.execute("DROP TABLE #TempTable") cursor.close() conn.close() File "D:\Git\temp\convertBakUp2SQL.py", line 18, in cursor.execute("INSERT INTO TempTable (D) VALUES (?)", backup_data) pyodbc.Error: ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver]Warning: Partial insert/update. The insert/update of a text or image column(s) did not succeed. (0) (SQLPutData); [HY000] [Microsoft][ODBC SQL Server Driver][SQL Server]The text, ntext, or image pointer value conflicts with the column name specified. (7125)')
The text, ntext, or image pointer value conflicts with the column name specified. (7125)') I heard that the error can be caused by the file size, so I tested it with a small file, but there was no progress at all.
In doing this, the .bak file backed up in the 2018 version of SQL Server cannot be restored in the 2017 version, so the intention is to restore all data by changing the insert statement. Please help if there is anything that needs to be fixed
Источник: https://stackoverflow.com/questions/781 ... t-data-for
With help from ChatGPT, I received the code below and am checking it, but I don't know why the error occurs. Please help me
import pyodbc conn_str = 'DRIVER={SQL Server};Server=myserver;Database=mydatabase;Trusted_Connection=True' # create connection conn = pyodbc.connect(conn_str) # backup path backup_file_path = 'D:\\Test.bak' cursor = conn.cursor() cursor.execute("CREATE TABLE #TempTable (D VARBINARY(MAX))") with open(backup_file_path, 'rb') as f: backup_data = f.read() cursor.execute("INSERT INTO #TempTable (D) VALUES (?)", backup_data) select_query = "SELECT data FROM #TempTable" for row in cursor.execute(select_query): backup_data = row[0].decode('utf-8') table_data = backup_data.split("INSERT INTO ") for table_insert in table_data[1:]: table_name = table_insert.split()[0] values_start_index = table_insert.find("VALUES") + len("VALUES") table_values = table_insert[values_start_index:].strip().strip(";") insert_script = f"INSERT INTO {table_name} {table_values};" print(insert_script) cursor.execute("DROP TABLE #TempTable") cursor.close() conn.close() File "D:\Git\temp\convertBakUp2SQL.py", line 18, in cursor.execute("INSERT INTO TempTable (D) VALUES (?)", backup_data) pyodbc.Error: ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver]Warning: Partial insert/update. The insert/update of a text or image column(s) did not succeed. (0) (SQLPutData); [HY000] [Microsoft][ODBC SQL Server Driver][SQL Server]The text, ntext, or image pointer value conflicts with the column name specified. (7125)')
The text, ntext, or image pointer value conflicts with the column name specified. (7125)') I heard that the error can be caused by the file size, so I tested it with a small file, but there was no progress at all.
In doing this, the .bak file backed up in the 2018 version of SQL Server cannot be restored in the 2017 version, so the intention is to restore all data by changing the insert statement. Please help if there is anything that needs to be fixed
Источник: https://stackoverflow.com/questions/781 ... t-data-for
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как лучше всего создать резервную копию данных на устройстве Android? [закрыто]
Anonymous » » в форуме Android - 0 Ответы
- 28 Просмотры
-
Последнее сообщение Anonymous
-