質問するログイン新規登録

質問編集履歴

2

タグの変更

2019/02/13 02:18

投稿

kirinsan
kirinsan

スコア13

title CHANGED
File without changes
body CHANGED
File without changes

1

ソースの記載

2019/02/13 02:18

投稿

kirinsan
kirinsan

スコア13

title CHANGED
File without changes
body CHANGED
@@ -38,4 +38,182 @@
38
38
  |table_lock_wait_timeout|50|
39
39
  |wait_timeout|28800|
40
40
 
41
- よろしくお願いします。
41
+ よろしくお願いします。
42
+
43
+
44
+ === 追記 ===
45
+ ソースは以下のように記述しています。
46
+
47
+ ```ASP.net
48
+ Dim SE As New clsDbAccess
49
+ Dim MySqlSE As New clsMySqlAccess
50
+
51
+ '***** MySql接続設定開始 *****
52
+ MySqlSE.ConnectionString = "接続文字列"
53
+ MySqlSE.CommandTimeout = CommandTimeout
54
+
55
+ '### トランザクション
56
+ MySqlSE.BeginTransaction()
57
+ '***** MySql接続設定終了 *****
58
+
59
+ '### 接続コネクション設定(SqlServer)
60
+ SE.ConnectionString = "接続文字列"
61
+ SE.CommandTimeout = CommandTimeout
62
+
63
+ '### トランザクション
64
+ SE.BeginTransaction()
65
+
66
+ '
67
+ 'SQLServerに対する更新処理
68
+ '~~
69
+ '
70
+
71
+ 'SQLServer⇒MySQLへのデータ流し込み
72
+
73
+ ''deleteその1
74
+ strSQL = "DELETE FROM tableA_MySQL WHERE ~"
75
+
76
+ MySqlSE.CommandString = strSQL
77
+ MySqlSE.ExecuteTSQL()
78
+
79
+ ''selectその1
80
+ strSQL = "SELECT * FROM tableB_SQLServer WHERE ~"
81
+
82
+ SE.TableName = "RESULT"
83
+ SE.CommandString = strSQL
84
+ SE.ExecuteSQL()
85
+
86
+ Dim DT_TMP As DataTable = Nothing
87
+ DT_TMP = SE.TableData.Tables(SE.TableName)
88
+
89
+ For i = 0 To DT_TMP.Rows.Count - 1
90
+ ''insertその1
91
+ strSQL = " INSERT INTO tableC_MySQL (~) VALUES (~) "
92
+
93
+ MySqlSE.CommandString = strSQL
94
+ MySqlSE.ExecuteTSQL()
95
+ Next
96
+
97
+ ''deleteその2
98
+ strSQL = "DELETE FROM tableD_MySQL WHERE ~"
99
+
100
+ MySqlSE.CommandString = strSQL
101
+ MySqlSE.ExecuteTSQL()
102
+
103
+ ''selectその2
104
+ strSQL = "SELECT * FROM tableE_SQLServer WHERE ~"
105
+
106
+ SE.TableName = "RESULT"
107
+ SE.CommandString = strSQL
108
+ SE.ExecuteSQL()
109
+
110
+ Dim DT_TMP As DataTable = Nothing
111
+ DT_TMP = SE.TableData.Tables(SE.TableName)
112
+
113
+ For i = 0 To DT_TMP.Rows.Count - 1
114
+ ''insertその2
115
+ strSQL = " INSERT INTO tableF_MySQL (~) VALUES (~) "
116
+
117
+ MySqlSE.CommandString = strSQL
118
+ MySqlSE.ExecuteTSQL()
119
+ Next
120
+
121
+ ''deleteその3
122
+ strSQL = "DELETE FROM tableG_MySQL WHERE ~"
123
+
124
+ MySqlSE.CommandString = strSQL
125
+ MySqlSE.ExecuteTSQL()
126
+
127
+ ''selectその3
128
+ strSQL = "SELECT * FROM tableH_SQLServer WHERE ~"
129
+
130
+ SE.TableName = "RESULT"
131
+ SE.CommandString = strSQL
132
+ SE.ExecuteSQL()
133
+
134
+ Dim DT_TMP As DataTable = Nothing
135
+ DT_TMP = SE.TableData.Tables(SE.TableName)
136
+
137
+ For i = 0 To DT_TMP.Rows.Count - 1
138
+ ''insertその3
139
+ strSQL = " INSERT INTO tableI_MySQL (~) VALUES (~) "
140
+
141
+ MySqlSE.CommandString = strSQL
142
+ MySqlSE.ExecuteTSQL()
143
+ Next
144
+
145
+ '### コミット(SqlServer)
146
+ SE.Commit()
147
+
148
+ '### コミット(MySql)
149
+ MySqlSE.Commit()
150
+
151
+
152
+
153
+
154
+ '' クラス定義
155
+ Public Class clsMySqlAccess
156
+ Public Function ExecuteTSQL() As Boolean
157
+
158
+ 'トランザクションが開始されているかどうか
159
+ If _sqlTransaction Is Nothing Then
160
+ OpenConnection()
161
+ _sqlCommand = New MySqlCommand(_commandString, _sqlConnection)
162
+ _sqlCommand = _sqlConnection.CreateCommand
163
+
164
+ _sqlCommand.CommandTimeout = _commandTimeout
165
+ Else
166
+ _sqlCommand = New MySqlCommand(_commandString, _sqlConnection)
167
+ _sqlCommand.Transaction = _sqlTransaction
168
+ _sqlCommand.CommandTimeout = _commandTimeout
169
+ End If
170
+
171
+ _executeCount = _sqlCommand.ExecuteNonQuery()
172
+
173
+ If _sqlTransaction Is Nothing Then
174
+ CloseConnection()
175
+ End If
176
+
177
+ Return True
178
+
179
+ End Function
180
+ End Class
181
+
182
+ Public Class clsDbAccess
183
+ Public Function ExecuteSQL() As Boolean
184
+
185
+ Dim DS As New DataSet()
186
+
187
+ 'トランザクションが開始されているかどうか
188
+ If _sqlTransaction Is Nothing Then
189
+ OpenConnection()
190
+ _sqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter()
191
+ _sqlDataAdapter.SelectCommand = New System.Data.SqlClient.SqlCommand(_commandString, _sqlConnection)
192
+ _sqlDataAdapter.SelectCommand.CommandTimeout = _commandTimeout
193
+ Else
194
+ _sqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter()
195
+ _sqlDataAdapter.SelectCommand = New System.Data.SqlClient.SqlCommand(_commandString, _sqlConnection)
196
+ _sqlDataAdapter.SelectCommand.Transaction = _sqlTransaction
197
+ _sqlDataAdapter.SelectCommand.CommandTimeout = _commandTimeout
198
+ End If
199
+
200
+ 'DataSetにSelect結果を格納
201
+ _sqlDataAdapter.Fill(DS, _tableName)
202
+ _executeCount = DS.Tables(0).Rows.Count
203
+
204
+ _tableData = DS
205
+
206
+ If _sqlTransaction Is Nothing Then
207
+ CloseConnection()
208
+ End If
209
+
210
+ Return True
211
+
212
+ End Function
213
+ End Class
214
+
215
+
216
+
217
+
218
+
219
+ ```