SQL讀取非本地excel或mdb檔

2021-08-19 23:47:07 字數 511 閱讀 9183

近期由於文件管理的需要, 統一將上傳檔案存放至一台專的檔案主機, 但是這樣一來由於文件與sqlserver不在同一主機, 使得原來的上傳excel和mdb檔的匯入資料功能不能執行, 原因是sqlserver不能直接讀取非本地的文件. 查詢了一下資料, 在sqlserver裡使用 xp_cmdshell 執行net use 命令來對映共享資料夾到本地就可以讀取. 直接在電腦裡做乙個對映網路驅動器不能執行, 必須在sqlserver裡用xp_cmdsheel執行 net use 命令來對映資源才行. 

命令:xp_cmdshell 'net use  z: \\192.168.16.11\d$ password /user:192.168.16.11\administrator'

"z:"為對映的碟符;

"\\192.168.16.11\d$"為共享目錄,ip可以換成電腦名;

"password"為登入共享主機的密碼;

"192.168.16.11\administrator"為登入共享主機ip和帳戶, 其中ip可換成電腦名; 

讀取本地EXCEL檔案

data it excel like alsmex tabline occurs 0with header line.parameters fn like rlgrap filename memory id mo1.at selection screen onvalue request for fn...

讀取Excel或Access至DataTable

region excel格式 string strconn strconn provider microsoft.jet.oledb.4.0 data source filename extended properties excel 8.0 oledbconnection myoledbconne...

python讀取excel資料插入sqlite中

usr bin env python coding utf 8 author hogan import xlrd import sqlite3 def read excel filename 開啟檔案excel workbook xlrd.open workbook filename 開啟 tabl...