簡體   English   中英

SQL bcp 信號量超時期限已過

[英]SQL bcp The semaphore timeout period has expired

我正在批量復制到我的數據庫中的一個選擇文件。

DECLARE @cmd varchar(1000)
DECLARE @sql varchar(8000) 
SET @cmd='"select * from [MyDB].[dbo].MyTable"' 
SELECT @sql = 'bcp '+@cmd+' queryout C:\myfile.txt -c -t -T -S MyServer -U user -P password';
exec xp_cmdshell @sql;

如果我更改參數並在我的機器上的數據庫測試上執行相同的命令,它可以工作,但在數據庫服務器上我收到此錯誤:

Msg 121, Level 20, State 0, Line 0
A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The semaphore timeout period has expired.)

我檢查了服務器名稱、用戶、密碼、表名,它們是正確的,所以我無法理解我做錯了什么。 有人可以幫我解決這個問題嗎? 謝謝

增加連接字符串中的超時秒數。

 private static void OpenSqlConnection() { string connectionString = GetConnectionString(); using(SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); Console.WriteLine("State: {0}", connection.State); Console.WriteLine("ConnectionTimeout: {0}", connection.ConnectionTimeout); } } static private string GetConnectionString() { // To avoid storing the connection string in your code, // you can retrieve it from a configuration file, using the // System.Configuration.ConfigurationSettings.AppSettings property return "Data Source=(local);Initial Catalog=AdventureWorks;" + "Integrated Security=SSPI;Connection Timeout=30"; }

我有同樣的錯誤。 第三方工具連接到數據庫以提取數據以導入商業智能系統。 每次提取/導入將運行大約 1 小時,並且在此過程中會有大約 10 到 15 個單獨的查詢。 幸運的是,我們已經登錄了——所以我們知道每個查詢的開始和結束時間。 提取/導入過程說它在 30 分鍾后成功完成 - 而不是大約需要 1 小時。 我能夠隔離過程失敗的查詢。 當我在 SSMS 中運行該查詢時,我遇到了您在問題中給出的相同錯誤。

但是,當我在另一個環境中運行該查詢時,我收到一個錯誤,即子查詢不能返回多於一行。

果然,當我在 prod 環境中注釋掉我的子查詢時,查詢運行沒有任何錯誤。

所以最終,我的根本原因是一個返回不止一行的子查詢——這個問題只是因為某種原因出現,“壞數據”進入了數據庫——即。 那個特定的子查詢不應該發現有不止一行的場景,因此,錯誤也開始出現在某一天。 (對於間歇性遇到此錯誤的其他人 - 可能是因為只有您的某些查詢 - 或您的查詢之一 - 失敗了)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM