我不得不使用BCP命令行工具將數據從SQL服務器數據庫導出到一個文件中的一個紅色的時候它拋出的錯誤時,既不給出的結果也沒有輸出任何東西帽子服務器。 我(顯然)使用有效的陳述,但bcp沒有產生任何類型的輸出/結果。 但是,當我執行缺少或無效參數的語句時,它會顯示相應的錯誤。 我正在查找此問題的原因(例如安裝有缺陷,使用不當,bcp,缺少權限或任何其他已知衝突)以及如何解決此問題。BCP使用有效的聲明,但傳遞的參數無效
BCP聲明:
bcp fully_qualified_table_name out ./data.txt -c -S server -U user -P password
BCP用法:
usage: /opt/microsoft/bin/bcp {dbtable | query} {in | out | queryout | format} datafile
[-m maxerrors] [-f formatfile] [-e errfile]
[-F firstrow] [-L lastrow] [-b batchsize]
[-n native type] [-c character type] [-w wide character type]
[-N keep non-text native] [-q quoted identifier]
[-t field terminator] [-r row terminator]
[-a packetsize] [-K application intent]
[-S server name or DSN if -D provided] [-D treat -S as DSN]
[-U username] [-P password]
[-T trusted connection] [-v version] [-R regional enable]
[-k keep null values] [-E keep identity values]
[-h "load hints"] [-d database name]
BCP版本:
BCP - Bulk Copy Program for Microsoft SQL Server.
Copyright (C) Microsoft Corporation. All Rights Reserved.
Version: 11.0.2270.0
SQL Server版本(SELECT @@VERSION
):
Microsoft SQL Server 2012 - 11.0.5058.0 (X64)
May 14 2014 18:34:29
Copyright (c) Microsoft Corporation
Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600:) (Hypervisor)
分佈:
Red Hat Enterprise Linux 6.7 (KornShell).
與相應的錯誤信息(示例)無效語句。
bcp THAT_TUB_ACE.oh_nerd.table_name out ./data.txt -c -S sr._bear -U you_sr. -P pass_sword
SQLState = S1T00, NativeError = 0
Error = [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]Login timeout expired
SQLState = 08001, NativeError = 11001
Error = [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]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.
SQLState = 08001, NativeError = 11001
Error = [unixODBC][Microsoft][ODBC Driver 11 for SQL Server]TCP Provider: Error code 0x2AF9
...
bcp fully_qualified_table_name ./data.txt -c -S valid_server -U valid_user -P bad_word
bcp fully_qualified_table_name out ./data.txt -c -S valid_server -U valid_user -P bad_word
SQLState = 28000, NativeError = 18456
Error = [unixODBC][Microsoft][ODBC Driver 11 for SQL Server][SQL Server]Login failed for user 'valid_user'.
摘要。
的目標是使用下面的語法(或類似)來生成數據文件:
bcp fully_qualified_table_name out ./data.txt -c -S server -U user -P password
事實是:
- 當運行一個有效BCP聲明沒有什麼窗口根本沒有輸出,也沒有創建數據文件。
- 我不能爲BCP使用(使用集成的安全可信的連接)選項
-T
所以我必須指定服務器,用戶名和密碼。 - 嘗試
queryout
選項上一個非常簡單的小桌子已經但仍然沒有運氣。 - 憑證有效,我使用
sqlcmd
成功對其進行了測試,如下所示:sqlcmd -S server -U user -P password -Q 'SELECT * FROM really_small_table'
。 - 的BCP下「無效的聲明與相應的錯誤信息(例子)」這個問題部分陳述只是無效聲明的例子表明,BCP實際上做的東西,但給出預期的結果。
您的用戶是否有寫入權限的文件夾要寫輸出文件?由於BCP先嚐試連接到SQL服務器,因此獲取錯誤憑證的錯誤屬於正常情況,所以如果失敗,它將不會嘗試執行其他任何操作。 –
嗨@IonutTulai,權限是正確的。 –