0

这是我的配置:

  • 视窗 7 专业版 64b SP1
  • 微软 SQL 服务器 2014 -
  • Microsoft SQL Server 管理工作室 12.0.2000.8
  • Microsoft .NET Framewrok 4.5.1 SDK
  • 微软视觉工作室 2013 (v12)

当我尝试运行以下查询时遇到问题:

declare @date datetime
set @date='9/12/2014 15:58:06’

    SELECT  TOP 1000 Articolo1.id as 'Articolo1.id' , Articolo1.nome as 'Articolo1.nome' 
    FROM Articolo as Articolo1 WITH (NOLOCK)  
    WHERE ((Articolo1.dataUltimaModifica  >=  @date)) 
     AND NOT EXISTS (
         SELECT [TabPagExt].[TabPag_Id] AS [TabPag_Id]
         FROM ( SELECT TOP 1000 Articolo1_PAG.[Id] AS [TabPag_Id]  
                FROM Articolo as Articolo1_PAG WITH (NOLOCK)
                WHERE ((Articolo1_PAG.dataUltimaModifica  >=  @date)) 
                ORDER BY  Articolo1_PAG.dataUltimaModifica ASC 
               )  AS [TabPagExt] WHERE Articolo1.[Id] = [TabPagExt].[TabPag_Id]
     ) 
    ORDER BY  Articolo1.dataUltimaModifica ASC

如果我在 SSMS(SQL Server Management Studio)中启动它,它运行没有问题,但是当我在 ADO.net 中尝试它时,它会抛出一个错误:

System.Data.SqlClient.SqlException:超时。

两者都是针对同一机器和连接中的生产服务器启动的。

这是源代码:

private void button1_Click(object sender, EventArgs e)
{
            SqlConnection conn = new SqlConnection(@"Server=mypc\sqlpass2014;Database=myDB;User Id=id;Password=pass;");
            SqlCommand command = new SqlCommand();
            command.CommandTimeout = 150;
            command.Connection = conn;
            conn.Open();
            //command.CommandText = "SET ARITHABORT ON ";
            //command.ExecuteNonQuery();
            command.CommandText = "SELECT TOP 1000 Articolo1.id as 'Articolo1.id' , Articolo1.nome as 'Articolo1.nome' FROM Articolo as Articolo1 WITH (NOLOCK)  WHERE ((Articolo1.dataUltimaModifica  >=  @Articolo1_dataUltimaModificaxxxxx0)) AND NOT EXISTS (SELECT [TabPagExt].[TabPag_Id] AS [TabPag_Id] FROM ( SELECT TOP 1000 Articolo1_PAG.[Id] AS [TabPag_Id]  FROM Articolo as Articolo1_PAG WITH (NOLOCK) WHERE ((Articolo1_PAG.dataUltimaModifica  >=  @Articolo1_dataUltimaModificaxxxxx0)) ORDER BY  Articolo1_PAG.dataUltimaModifica ASC )  AS [TabPagExt] WHERE Articolo1.[Id] = [TabPagExt].[TabPag_Id])  ORDER BY  Articolo1.dataUltimaModifica ASC  ";
            command.Parameters.Add(new SqlParameter("@Articolo1_dataUltimaModificaxxxxx0", new DateTime(2014, 12, 9, 15, 58, 06)));
            try
            {
                SqlDataReader reader = command.ExecuteReader();

                int rows = 0;
                try
                {
                    while (reader.Read())
                        rows++;
                }
                finally
                {
                    reader.Close();
                }
                MessageBox.Show("Rows read: " + rows.ToString());
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString());
            }
            finally
            {
                conn.Close();
            }
}

我已经尝试了在 StackOverflow 中已经看到的类似案例中给出的所有解决方案(我认为是这样),但没有一个对我有用。

关于问题根源和可能的解决方案/解决方法的任何线索?

提前感谢大家的帮助,

米尔科

4

0 回答 0