【问题标题】:SQL bcp The semaphore timeout period has expiredSQL bcp 信号量超时期限已过
【发布时间】:2014-04-13 10:16:02
【问题描述】:

我正在对我的数据库中的一个选择文件进行批量复制。

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.)

我检查了服务器名称、用户、密码、表名,它们都是正确的,所以我无法理解我做错了什么。 有人可以帮我解决这个问题吗? 谢谢

【问题讨论】:

标签: sql sql-server timeout bcp


【解决方案1】:

增加连接字符串中的超时秒数。

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";
}

【讨论】:

    【解决方案2】:

    我有同样的错误。第三方工具连接到数据库以提取数据以导入商业智能系统。每个提取/导入将运行大约 1 小时,并且在此过程中会有大约 10 到 15 个单独的查询。幸运的是,我们已经登录了——所以我们知道每个查询的开始和结束时间。提取/导入过程说它在 30 分钟后成功完成 - 而不是大约 1 小时。我能够隔离过程失败的查询。当我在 SSMS 中运行该查询时,我得到了与您在问题中给出的相同的错误。

    但是,当我在另一个环境中运行该查询时,我收到一个错误,即子查询不能返回多于一行。

    果然,当我在 prod 环境中注释掉我的子查询时,查询运行没有任何错误。

    所以最终,对我来说,根本原因是子查询返回多行 - 问题出现只是因为出于某种原因,“坏数据”进入了数据库 - 即。该特定子查询永远不会发现存在多于一行的情况,因此错误也只是一天才开始出现。 (对于间歇性遇到此错误的其他人 - 这可能是因为只有您的一些查询 - 或您的一个查询 - 失败了)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-03
      • 2015-08-05
      • 1970-01-01
      • 2014-09-24
      • 2012-12-09
      • 2017-02-06
      • 1970-01-01
      相关资源
      最近更新 更多