質問編集履歴
2
修正コード追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,4 +72,69 @@
|
|
72
72
|
データベースは別サーバの共有フォルダにあります。
|
73
73
|
|
74
74
|
|
75
|
+
2022/12/12 追記
|
75
76
|
|
77
|
+
下記コードのreturn response;の1行が、時々非常に遅い(15秒)ことがあることがわかりました。
|
78
|
+
|
79
|
+
```C#
|
80
|
+
public HttpResponseMessage GetWorkResultsByDate(string div, string datefrom, string dateto)
|
81
|
+
{
|
82
|
+
var sw = new System.Diagnostics.Stopwatch();
|
83
|
+
sw.Start();
|
84
|
+
|
85
|
+
try
|
86
|
+
{
|
87
|
+
DBType dbtype = DBType.Access;
|
88
|
+
string connectionString = DBConnectionString.GetConnection(div, ref dbtype);
|
89
|
+
using (OleDbConnection cn = new OleDbConnection(connectionString))
|
90
|
+
{
|
91
|
+
cn.Open();
|
92
|
+
string sql = "SELECT * FROM testテーブル WHERE 日付 >= ? AND 日付 <= ?";
|
93
|
+
OleDbCommand cmd = new OleDbCommand(sql, cn);
|
94
|
+
cmd.Parameters.Add("@開始", OleDbType.Date).Value = datefrom;
|
95
|
+
cmd.Parameters.Add("@終了", OleDbType.Date).Value = dateto;
|
96
|
+
DataTable dt = new DataTable();
|
97
|
+
OleDbDataAdapter ada = new OleDbDataAdapter(cmd);
|
98
|
+
ada.Fill(dt);
|
99
|
+
|
100
|
+
//↓速度改善試行
|
101
|
+
IEnumerable<WorkResult> rtnList = dt.AsEnumerable().Select(row => new WorkResult
|
102
|
+
{
|
103
|
+
xxxxx= Convert.ToInt32(row["ID"]),
|
104
|
+
|
105
|
+
}).ToList();
|
106
|
+
//↑速度改善試行
|
107
|
+
|
108
|
+
sw.Stop();
|
109
|
+
Logger.WriteLog(MethodBase.GetCurrentMethod().Name, $"{sw.Elapsed.TotalSeconds}秒");
|
110
|
+
sw.Reset();
|
111
|
+
sw.Start();
|
112
|
+
|
113
|
+
//return Request.CreateResponse(HttpStatusCode.OK, rtnList); //速度改善試行
|
114
|
+
var response = Request.CreateResponse(HttpStatusCode.OK);
|
115
|
+
response.Content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(rtnList, Newtonsoft.Json.Formatting.Indented), System.Text.Encoding.UTF8, "application/json");
|
116
|
+
|
117
|
+
sw.Stop();
|
118
|
+
Logger.WriteLog(MethodBase.GetCurrentMethod().Name, $"CheckPoint {sw.Elapsed.TotalSeconds}秒");
|
119
|
+
sw.Reset();
|
120
|
+
sw.Start();
|
121
|
+
|
122
|
+
return response;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
catch (Exception ex)
|
126
|
+
{
|
127
|
+
Logger.WriteLog(MethodBase.GetCurrentMethod().Name, ex.Message);
|
128
|
+
MyApiError err = new MyApiError();
|
129
|
+
err.ErrorMessage = ex.Message;
|
130
|
+
return Request.CreateResponse(HttpStatusCode.OK, err);
|
131
|
+
}
|
132
|
+
finally
|
133
|
+
{
|
134
|
+
sw.Stop();
|
135
|
+
Logger.WriteLog(MethodBase.GetCurrentMethod().Name, $"finally {sw.Elapsed.TotalSeconds}秒");
|
136
|
+
}
|
137
|
+
}
|
138
|
+
```
|
139
|
+
|
140
|
+
|
1
[追記]
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,4 +67,9 @@
|
|
67
67
|
|
68
68
|
### 補足情報(FW/ツールのバージョンなど)
|
69
69
|
|
70
|
+
[追記]
|
71
|
+
関数内でAccessのデーベースにアクセスしています。
|
72
|
+
データベースは別サーバの共有フォルダにあります。
|
70
73
|
|
74
|
+
|
75
|
+
|