我在嘗試通過 bcp 將 CSV 文件上傳到 Azure MS SQL 數據庫時遇到問題。我正在使用Bcpy工具來實現這一點。這是我正在運行的腳本:sql_config = { 'server': 'sql_server_hostname', 'database': 'database_name', 'username': 'user', 'password': 'password' } sql_table_name = 'test_data1' csv_file_path = 'data1.csv' #File in the script directory flat_file = bcpy.FlatFile(qualifier='', path=csv_file_path) sql_table = bcpy.SqlTable(sql_config, table=sql_table_name) flat_file.to_sql(sql_table)運行腳本后,我收到以下錯誤:<ipython-input-11-97d18f6b2041> in function() 263 flat_file = bcpy.FlatFile(qualifier='', path=csv_file_path) 264 sql_table = bcpy.SqlTable(sql_config, table=sql_table_name)--> 265 flat_file.to_sql(sql_table) 266 267 c:\users\user\appdata\local\programs\python\python37\lib\site-packages\bcpy\data_objects.py in to_sql(self, sql_table, use_existing_sql_table, batch_size) 157 ), 158 username=sql_table.username,--> 159 password=sql_table.password) 160 bcp(sql_table=sql_table, flat_file=self, batch_size=batch_size) 161 c:\users\user\appdata\local\programs\python\python37\lib\site-packages\bcpy\binary_callers.py in sqlcmd(server, database, command, username, password) 81 ['-s,', '-W', '-Q', command] 82 result = subprocess.run(sqlcmd_command, stdout=subprocess.PIPE,---> 83 stderr=subprocess.PIPE) 84 if result.returncode: 85 result_dump = str(result).replace(password, sha512(password))填充“sql_table_name”參數時,我嘗試使用“test_data1”和“dbo.test_data1”。由于它是一個 Azure MS SQL 數據庫,因此服務器參數的寫法如下:“servername.database.windows.net”你知道這可能是什么原因嗎?您知道將 CSV 文件上傳到我的數據庫的任何其他選項嗎?
2 回答

慕桂英4014372
TA貢獻1871條經驗 獲得超13個贊
錯誤是:
FileNotFoundError: [WinError 2] The system cannot find the specified file
你確定以下行
csv_file_path = 'data1.csv' #File in the script directory
是文件的完整路徑嗎?
添加回答
舉報
0/150
提交
取消