私たちには深刻な問題が発生しているという報告がありますので、問題のトラブルシューティングを行うためにコンソールアプリケーションに入れることにしました。異常なSQL /データの問題
レポートはSQLからの単純な単一選択で、およそ25列、 を返し、私たちの日付範囲は3〜6ヶ月で、10k行を戻すことができるので、多くのデータについては言及していません。レポートを実行するとき、それは私たちのウェブサイトからタイムアウトされ、起こっていただきました。ここ
は、コンソールで、完了するために13-18分からどこでも要し、待ち時間は今
da.Fill(ds);
で発生するようですここでは奇妙なことですが、SQL Server Management Studio内で約1〜3秒で実行されます.Delphi開発者が同様のアプリケーションを作成すると数秒で実行されますが、これは.NETを使用してのみ発生します。
このコードを使用して ..
using (var dr = _command.ExecuteReader()) { if (dr.HasRows) { int i = 0; while (dr.Read()) { var startRead = DateTime.Now; Console.Write("{2}\t{0}\t{1}\t", dr.GetInt32(0), dr.GetString(1), i); var tookRead = DateTime.Now.Subtract(startRead); Console.WriteLine("Took: " + tookRead); i++; } }しかし、それはまったく助けにはなりませんでしたが、それはちょうどチャックに表示されますが、頻繁な遅延があります。私はそのSQLを考えていますが、なぜそれがDelphiとSQL Management Studioでうまく動作するのか説明できません。
私は.NET 2.0、3.5、4を使用しようとしましたが、すべてのフレームワークで発生します。ここで
は私のコード
public static DataSet GetData() { var now = DateTime.Now; var _command = new SqlCommand(); var _connection = new SqlConnection(); try { _connection.ConnectionString = connectionString; _command.Connection = _connection; _command.CommandText = storedProcedure; _command.CommandType = CommandType.StoredProcedure; _command.CommandTimeout = 60; if (string.IsNullOrEmpty(_connection.ConnectionString)) { throw new Exception("Connection String was not supplied"); } _command.Parameters.Add(new SqlParameter("DateFrom", dateFrom)); _command.Parameters.Add(new SqlParameter("DateTo", dateTo)); SqlDataAdapter da; var ds = new DataSet(); _connection.Open(); var done = DateTime.Now; da = new SqlDataAdapter(_command); da.Fill(ds); if (ds == null) { throw new Exception("DataSet is null."); } if (ds.Tables.Count == 0) { throw new Exception("Table count is 0"); } var took = done.Subtract(now); return ds; } catch (Exception ex) { File.WriteAllText(Path.Combine(Application.StartupPath, String.Format("Exception{0:MMddyyyy_HHmmss}.log", DateTime.Now)), ex.ToString()); } finally { if (_connection.State != ConnectionState.Closed) { _connection.Close(); } } return null; }
任意のアイデアがありますか?私たちのDBAは、フレームワークを非難されて、私は実際に
IF ... .. SQLで(多分統計、または破損デシベル)
クエリがSSMS内から正常に実行されると、どのようにそれがSQLと思われますか? – JNK
は、SQL文を実行した後、SQL Management studionの最後の行までスクロールしましたか? – Yahia
は、このスレッドを見てください: http://stackoverflow.com/questions/250713/sqldataadapter-fill-method-slow – granaker