aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
diff options
context:
space:
mode:
authorCharles Krinke2008-07-17 13:43:31 +0000
committerCharles Krinke2008-07-17 13:43:31 +0000
commite8412dcd42f6478f70f587d534a92a948cd6dd93 (patch)
treee3f2d084da7f40bd453bf06fefa43241facc0f86 /OpenSim/Data/MSSQL/MSSQLInventoryData.cs
parentmorphing OSHttpHandler interface into an abstract base class. adding (diff)
downloadopensim-SC_OLD-e8412dcd42f6478f70f587d534a92a948cd6dd93.zip
opensim-SC_OLD-e8412dcd42f6478f70f587d534a92a948cd6dd93.tar.gz
opensim-SC_OLD-e8412dcd42f6478f70f587d534a92a948cd6dd93.tar.bz2
opensim-SC_OLD-e8412dcd42f6478f70f587d534a92a948cd6dd93.tar.xz
Mantis#1736. Thank you kindly, StrawberryFride for a patch that:
Many issues with handling connections in MSSQL, have rearchitected to ensure that connections are always opened and closed in a timely fashion & disposed of cleanly, and removed unnecessary lock statements. SQL Server performance seems to have improved considerably as a result, and various timeout errors seem to have been fixed.
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLInventoryData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLInventoryData.cs357
1 files changed, 170 insertions, 187 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
index 3177325..4a8d6e9 100644
--- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
@@ -67,12 +67,12 @@ namespace OpenSim.Data.MSSQL
67 public void Initialise(string connect) 67 public void Initialise(string connect)
68 { 68 {
69 // TODO: actually use the provided connect string 69 // TODO: actually use the provided connect string
70 IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); 70 IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
71 string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); 71 string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
72 string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); 72 string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
73 string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); 73 string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
74 string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); 74 string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
75 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); 75 string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
76 76
77 database = 77 database =
78 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, 78 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
@@ -165,29 +165,26 @@ namespace OpenSim.Data.MSSQL
165 { 165 {
166 try 166 try
167 { 167 {
168 lock (database) 168 List<InventoryItemBase> items = new List<InventoryItemBase>();
169 {
170 List<InventoryItemBase> items = new List<InventoryItemBase>();
171 169
172 Dictionary<string, string> param = new Dictionary<string, string>(); 170 Dictionary<string, string> param = new Dictionary<string, string>();
173 param["parentFolderID"] = folderID.ToString(); 171 param["parentFolderID"] = folderID.ToString();
174 172
175 IDbCommand result = 173 using (IDbCommand result =
176 database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param); 174 database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param))
177 IDataReader reader = result.ExecuteReader(); 175 using (IDataReader reader = result.ExecuteReader())
176 {
178 177
179 while (reader.Read()) 178 while (reader.Read())
180 items.Add(readInventoryItem(reader)); 179 items.Add(readInventoryItem(reader));
181 180
182 reader.Close(); 181 reader.Close();
183 result.Dispose();
184
185 return items;
186 } 182 }
183
184 return items;
187 } 185 }
188 catch (Exception e) 186 catch (Exception e)
189 { 187 {
190 database.Reconnect();
191 m_log.Error(e.ToString()); 188 m_log.Error(e.ToString());
192 return null; 189 return null;
193 } 190 }
@@ -202,30 +199,26 @@ namespace OpenSim.Data.MSSQL
202 { 199 {
203 try 200 try
204 { 201 {
205 lock (database) 202 Dictionary<string, string> param = new Dictionary<string, string>();
206 { 203 param["uuid"] = user.ToString();
207 Dictionary<string, string> param = new Dictionary<string, string>(); 204 param["zero"] = LLUUID.Zero.ToString();
208 param["uuid"] = user.ToString();
209 param["zero"] = LLUUID.Zero.ToString();
210 205
211 IDbCommand result = 206 using (IDbCommand result =
212 database.Query( 207 database.Query(
213 "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); 208 "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param))
214 IDataReader reader = result.ExecuteReader(); 209 using (IDataReader reader = result.ExecuteReader())
210 {
215 211
216 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 212 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
217 while (reader.Read()) 213 while (reader.Read())
218 items.Add(readInventoryFolder(reader)); 214 items.Add(readInventoryFolder(reader));
219 215
220 reader.Close();
221 result.Dispose();
222
223 return items; 216 return items;
224 } 217 }
218
225 } 219 }
226 catch (Exception e) 220 catch (Exception e)
227 { 221 {
228 database.Reconnect();
229 m_log.Error(e.ToString()); 222 m_log.Error(e.ToString());
230 return null; 223 return null;
231 } 224 }
@@ -240,16 +233,15 @@ namespace OpenSim.Data.MSSQL
240 { 233 {
241 try 234 try
242 { 235 {
243 lock (database) 236 Dictionary<string, string> param = new Dictionary<string, string>();
244 { 237 param["uuid"] = user.ToString();
245 Dictionary<string, string> param = new Dictionary<string, string>(); 238 param["zero"] = LLUUID.Zero.ToString();
246 param["uuid"] = user.ToString();
247 param["zero"] = LLUUID.Zero.ToString();
248 239
249 IDbCommand result = 240 using (IDbCommand result =
250 database.Query( 241 database.Query(
251 "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param); 242 "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param))
252 IDataReader reader = result.ExecuteReader(); 243 using (IDataReader reader = result.ExecuteReader())
244 {
253 245
254 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 246 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
255 while (reader.Read()) 247 while (reader.Read())
@@ -267,15 +259,12 @@ namespace OpenSim.Data.MSSQL
267 rootFolder = items[0]; 259 rootFolder = items[0];
268 } 260 }
269 261
270 reader.Close();
271 result.Dispose();
272
273 return rootFolder; 262 return rootFolder;
274 } 263 }
264
275 } 265 }
276 catch (Exception e) 266 catch (Exception e)
277 { 267 {
278 database.Reconnect();
279 m_log.Error(e.ToString()); 268 m_log.Error(e.ToString());
280 return null; 269 return null;
281 } 270 }
@@ -290,30 +279,23 @@ namespace OpenSim.Data.MSSQL
290 { 279 {
291 try 280 try
292 { 281 {
293 lock (database) 282 Dictionary<string, string> param = new Dictionary<string, string>();
294 { 283 param["parentFolderID"] = parentID.ToString();
295 Dictionary<string, string> param = new Dictionary<string, string>();
296 param["parentFolderID"] = parentID.ToString();
297
298
299 IDbCommand result =
300 database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param);
301 IDataReader reader = result.ExecuteReader();
302 284
285 using (IDbCommand result =
286 database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param))
287 using (IDataReader reader = result.ExecuteReader())
288 {
303 List<InventoryFolderBase> items = new List<InventoryFolderBase>(); 289 List<InventoryFolderBase> items = new List<InventoryFolderBase>();
304 290
305 while (reader.Read()) 291 while (reader.Read())
306 items.Add(readInventoryFolder(reader)); 292 items.Add(readInventoryFolder(reader));
307 293
308 reader.Close();
309 result.Dispose();
310
311 return items; 294 return items;
312 } 295 }
313 } 296 }
314 catch (Exception e) 297 catch (Exception e)
315 { 298 {
316 database.Reconnect();
317 m_log.Error(e.ToString()); 299 m_log.Error(e.ToString());
318 return null; 300 return null;
319 } 301 }
@@ -369,28 +351,23 @@ namespace OpenSim.Data.MSSQL
369 { 351 {
370 try 352 try
371 { 353 {
372 lock (database) 354 Dictionary<string, string> param = new Dictionary<string, string>();
373 { 355 param["inventoryID"] = itemID.ToString();
374 Dictionary<string, string> param = new Dictionary<string, string>();
375 param["inventoryID"] = itemID.ToString();
376 356
377 IDbCommand result = 357 using (IDbCommand result =
378 database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param); 358 database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param))
379 IDataReader reader = result.ExecuteReader(); 359 using (IDataReader reader = result.ExecuteReader())
360 {
380 361
381 InventoryItemBase item = null; 362 InventoryItemBase item = null;
382 if (reader.Read()) 363 if (reader.Read())
383 item = readInventoryItem(reader); 364 item = readInventoryItem(reader);
384 365
385 reader.Close();
386 result.Dispose();
387
388 return item; 366 return item;
389 } 367 }
390 } 368 }
391 catch (Exception e) 369 catch (Exception e)
392 { 370 {
393 database.Reconnect();
394 m_log.Error(e.ToString()); 371 m_log.Error(e.ToString());
395 } 372 }
396 return null; 373 return null;
@@ -431,25 +408,22 @@ namespace OpenSim.Data.MSSQL
431 { 408 {
432 try 409 try
433 { 410 {
434 lock (database) 411 Dictionary<string, string> param = new Dictionary<string, string>();
435 { 412 param["uuid"] = folderID.ToString();
436 Dictionary<string, string> param = new Dictionary<string, string>();
437 param["uuid"] = folderID.ToString();
438 413
439 IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param); 414 using (IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param))
440 IDataReader reader = result.ExecuteReader(); 415 using (IDataReader reader = result.ExecuteReader())
416 {
441 417
442 reader.Read(); 418 reader.Read();
419
443 InventoryFolderBase folder = readInventoryFolder(reader); 420 InventoryFolderBase folder = readInventoryFolder(reader);
444 reader.Close();
445 result.Dispose();
446 421
447 return folder; 422 return folder;
448 } 423 }
449 } 424 }
450 catch (Exception e) 425 catch (Exception e)
451 { 426 {
452 database.Reconnect();
453 m_log.Error(e.ToString()); 427 m_log.Error(e.ToString());
454 return null; 428 return null;
455 } 429 }
@@ -479,9 +453,8 @@ namespace OpenSim.Data.MSSQL
479 + ", @inventoryBasePermissions, @inventoryEveryOnePermissions, @salePrice, @saleType" 453 + ", @inventoryBasePermissions, @inventoryEveryOnePermissions, @salePrice, @saleType"
480 + ", @creationDate, @groupID, @groupOwned, @flags);"; 454 + ", @creationDate, @groupID, @groupOwned, @flags);";
481 455
482 try 456 using (AutoClosingSqlCommand command = database.Query(sql))
483 { 457 {
484 SqlCommand command = new SqlCommand(sql, database.getConnection());
485 command.Parameters.AddWithValue("inventoryID", item.ID.ToString()); 458 command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
486 command.Parameters.AddWithValue("assetID", item.AssetID.ToString()); 459 command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
487 command.Parameters.AddWithValue("assetType", item.AssetType.ToString()); 460 command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
@@ -502,13 +475,16 @@ namespace OpenSim.Data.MSSQL
502 command.Parameters.AddWithValue("groupOwned", item.GroupOwned); 475 command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
503 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags)); 476 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
504 477
505 command.ExecuteNonQuery(); 478 try
506 command.Dispose(); 479 {
507 } 480 command.ExecuteNonQuery();
508 catch (SqlException e) 481 }
509 { 482 catch (SqlException e)
510 m_log.Error(e.ToString()); 483 {
484 m_log.Error(e.ToString());
485 }
511 } 486 }
487
512 } 488 }
513 489
514 /// <summary> 490 /// <summary>
@@ -517,7 +493,7 @@ namespace OpenSim.Data.MSSQL
517 /// <param name="item">Inventory item to update</param> 493 /// <param name="item">Inventory item to update</param>
518 public void updateInventoryItem(InventoryItemBase item) 494 public void updateInventoryItem(InventoryItemBase item)
519 { 495 {
520 SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " + 496 using (AutoClosingSqlCommand command = database.Query("UPDATE inventoryitems set inventoryID = @inventoryID, " +
521 "assetID = @assetID, " + 497 "assetID = @assetID, " +
522 "assetType = @assetType," + 498 "assetType = @assetType," +
523 "parentFolderID = @parentFolderID," + 499 "parentFolderID = @parentFolderID," +
@@ -529,42 +505,44 @@ namespace OpenSim.Data.MSSQL
529 "invType = @invType," + 505 "invType = @invType," +
530 "creatorID = @creatorID," + 506 "creatorID = @creatorID," +
531 "inventoryBasePermissions = @inventoryBasePermissions," + 507 "inventoryBasePermissions = @inventoryBasePermissions," +
532 "inventoryEveryOnePermissions = @inventoryEveryOnePermissions," + 508 "inventoryEveryOnePermissions = @inventoryEveryOnePermissions," +
533 "salePrice = @salePrice," + 509 "salePrice = @salePrice," +
534 "saleType = @saleType," + 510 "saleType = @saleType," +
535 "creationDate = @creationDate," + 511 "creationDate = @creationDate," +
536 "groupID = @groupID," + 512 "groupID = @groupID," +
537 "groupOwned = @groupOwned," + 513 "groupOwned = @groupOwned," +
538 "flags = @flags where " + 514 "flags = @flags where " +
539 "inventoryID = @keyInventoryID;", database.getConnection()); 515 "inventoryID = @keyInventoryID;"))
540 command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
541 command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
542 command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
543 command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
544 command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
545 command.Parameters.AddWithValue("inventoryName", item.Name);
546 command.Parameters.AddWithValue("inventoryDescription", item.Description);
547 command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
548 command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
549 command.Parameters.AddWithValue("invType", item.InvType);
550 command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
551 command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
552 command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
553 command.Parameters.AddWithValue("salePrice", item.SalePrice);
554 command.Parameters.AddWithValue("saleType", item.SaleType);
555 command.Parameters.AddWithValue("creationDate", item.CreationDate);
556 command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
557 command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
558 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
559 command.Parameters.AddWithValue("@keyInventoryID", item.ID.ToString());
560
561 try
562 {
563 command.ExecuteNonQuery();
564 }
565 catch (Exception e)
566 { 516 {
567 m_log.Error(e.ToString()); 517 command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
518 command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
519 command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
520 command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
521 command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
522 command.Parameters.AddWithValue("inventoryName", item.Name);
523 command.Parameters.AddWithValue("inventoryDescription", item.Description);
524 command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
525 command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
526 command.Parameters.AddWithValue("invType", item.InvType);
527 command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
528 command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
529 command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
530 command.Parameters.AddWithValue("salePrice", item.SalePrice);
531 command.Parameters.AddWithValue("saleType", item.SaleType);
532 command.Parameters.AddWithValue("creationDate", item.CreationDate);
533 command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
534 command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
535 command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
536 command.Parameters.AddWithValue("@keyInventoryID", item.ID.ToString());
537
538 try
539 {
540 command.ExecuteNonQuery();
541 }
542 catch (Exception e)
543 {
544 m_log.Error(e.ToString());
545 }
568 } 546 }
569 } 547 }
570 548
@@ -579,13 +557,13 @@ namespace OpenSim.Data.MSSQL
579 Dictionary<string, string> param = new Dictionary<string, string>(); 557 Dictionary<string, string> param = new Dictionary<string, string>();
580 param["uuid"] = itemID.ToString(); 558 param["uuid"] = itemID.ToString();
581 559
582 IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param); 560 using (IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param))
583 cmd.ExecuteNonQuery(); 561 {
584 cmd.Dispose(); 562 cmd.ExecuteNonQuery();
563 }
585 } 564 }
586 catch (SqlException e) 565 catch (SqlException e)
587 { 566 {
588 database.Reconnect();
589 m_log.Error(e.ToString()); 567 m_log.Error(e.ToString());
590 } 568 }
591 } 569 }
@@ -601,23 +579,24 @@ namespace OpenSim.Data.MSSQL
601 sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);"; 579 sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);";
602 580
603 581
604 SqlCommand command = new SqlCommand(sql, database.getConnection()); 582 using (AutoClosingSqlCommand command = database.Query(sql))
605 command.Parameters.AddWithValue("folderID", folder.ID.ToString());
606 command.Parameters.AddWithValue("agentID", folder.Owner.ToString());
607 command.Parameters.AddWithValue("parentFolderID", folder.ParentID.ToString());
608 command.Parameters.AddWithValue("folderName", folder.Name);
609 command.Parameters.AddWithValue("type", folder.Type);
610 command.Parameters.AddWithValue("version", Convert.ToInt32(folder.Version));
611
612 try
613 { 583 {
614 //IDbCommand result = database.Query(sql, param); 584 command.Parameters.AddWithValue("folderID", folder.ID.ToString());
615 command.ExecuteNonQuery(); 585 command.Parameters.AddWithValue("agentID", folder.Owner.ToString());
616 command.Dispose(); 586 command.Parameters.AddWithValue("parentFolderID", folder.ParentID.ToString());
617 } 587 command.Parameters.AddWithValue("folderName", folder.Name);
618 catch (Exception e) 588 command.Parameters.AddWithValue("type", folder.Type);
619 { 589 command.Parameters.AddWithValue("version", Convert.ToInt32(folder.Version));
620 m_log.Error(e.ToString()); 590
591 try
592 {
593 //IDbCommand result = database.Query(sql, param);
594 command.ExecuteNonQuery();
595 }
596 catch (Exception e)
597 {
598 m_log.Error(e.ToString());
599 }
621 } 600 }
622 } 601 }
623 602
@@ -627,35 +606,37 @@ namespace OpenSim.Data.MSSQL
627 /// <param name="folder">Folder to update</param> 606 /// <param name="folder">Folder to update</param>
628 public void updateInventoryFolder(InventoryFolderBase folder) 607 public void updateInventoryFolder(InventoryFolderBase folder)
629 { 608 {
630 SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " + 609 using (IDbCommand command = database.Query("UPDATE inventoryfolders set folderID = @folderID, " +
631 "agentID = @agentID, " + 610 "agentID = @agentID, " +
632 "parentFolderID = @parentFolderID," + 611 "parentFolderID = @parentFolderID," +
633 "folderName = @folderName," + 612 "folderName = @folderName," +
634 "type = @type," + 613 "type = @type," +
635 "version = @version where " + 614 "version = @version where " +
636 "folderID = @keyFolderID;", database.getConnection()); 615 "folderID = @keyFolderID;"))
637 SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString()); 616 {
638 SqlParameter param2 = new SqlParameter("@agentID", folder.Owner.ToString()); 617 SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString());
639 SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString()); 618 SqlParameter param2 = new SqlParameter("@agentID", folder.Owner.ToString());
640 SqlParameter param4 = new SqlParameter("@folderName", folder.Name); 619 SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
641 SqlParameter param5 = new SqlParameter("@type", folder.Type); 620 SqlParameter param4 = new SqlParameter("@folderName", folder.Name);
642 SqlParameter param6 = new SqlParameter("@version", Convert.ToInt32(folder.Version)); 621 SqlParameter param5 = new SqlParameter("@type", folder.Type);
643 SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString()); 622 SqlParameter param6 = new SqlParameter("@version", Convert.ToInt32(folder.Version));
644 command.Parameters.Add(param1); 623 SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString());
645 command.Parameters.Add(param2); 624 command.Parameters.Add(param1);
646 command.Parameters.Add(param3); 625 command.Parameters.Add(param2);
647 command.Parameters.Add(param4); 626 command.Parameters.Add(param3);
648 command.Parameters.Add(param5); 627 command.Parameters.Add(param4);
649 command.Parameters.Add(param6); 628 command.Parameters.Add(param5);
650 command.Parameters.Add(param7); 629 command.Parameters.Add(param6);
651 630 command.Parameters.Add(param7);
652 try 631
653 { 632 try
654 command.ExecuteNonQuery(); 633 {
655 } 634 command.ExecuteNonQuery();
656 catch (Exception e) 635 }
657 { 636 catch (Exception e)
658 m_log.Error(e.ToString()); 637 {
638 m_log.Error(e.ToString());
639 }
659 } 640 }
660 } 641 }
661 642
@@ -665,23 +646,25 @@ namespace OpenSim.Data.MSSQL
665 /// <param name="folder">Folder to update</param> 646 /// <param name="folder">Folder to update</param>
666 public void moveInventoryFolder(InventoryFolderBase folder) 647 public void moveInventoryFolder(InventoryFolderBase folder)
667 { 648 {
668 SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " + 649 using (IDbCommand command = database.Query("UPDATE inventoryfolders set folderID = @folderID, " +
669 "parentFolderID = @parentFolderID," + 650 "parentFolderID = @parentFolderID," +
670 "folderID = @keyFolderID;", database.getConnection()); 651 "folderID = @keyFolderID;"))
671 SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString());
672 SqlParameter param2 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
673 SqlParameter param3 = new SqlParameter("@keyFolderID", folder.ID.ToString());
674 command.Parameters.Add(param1);
675 command.Parameters.Add(param2);
676 command.Parameters.Add(param3);
677
678 try
679 {
680 command.ExecuteNonQuery();
681 }
682 catch (Exception e)
683 { 652 {
684 m_log.Error(e.ToString()); 653 SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString());
654 SqlParameter param2 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
655 SqlParameter param3 = new SqlParameter("@keyFolderID", folder.ID.ToString());
656 command.Parameters.Add(param1);
657 command.Parameters.Add(param2);
658 command.Parameters.Add(param3);
659
660 try
661 {
662 command.ExecuteNonQuery();
663 }
664 catch (Exception e)
665 {
666 m_log.Error(e.ToString());
667 }
685 } 668 }
686 } 669 }
687 670
@@ -721,13 +704,13 @@ namespace OpenSim.Data.MSSQL
721 Dictionary<string, string> param = new Dictionary<string, string>(); 704 Dictionary<string, string> param = new Dictionary<string, string>();
722 param["folderID"] = folderID.ToString(); 705 param["folderID"] = folderID.ToString();
723 706
724 IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param); 707 using (IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param))
725 cmd.ExecuteNonQuery(); 708 {
726 cmd.Dispose(); 709 cmd.ExecuteNonQuery();
710 }
727 } 711 }
728 catch (SqlException e) 712 catch (SqlException e)
729 { 713 {
730 database.Reconnect();
731 m_log.Error(e.ToString()); 714 m_log.Error(e.ToString());
732 } 715 }
733 } 716 }
@@ -744,14 +727,14 @@ namespace OpenSim.Data.MSSQL
744 param["parentFolderID"] = folderID.ToString(); 727 param["parentFolderID"] = folderID.ToString();
745 728
746 729
747 IDbCommand cmd = 730 using (IDbCommand cmd =
748 database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param); 731 database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param))
749 cmd.ExecuteNonQuery(); 732 {
750 cmd.Dispose(); 733 cmd.ExecuteNonQuery();
734 }
751 } 735 }
752 catch (SqlException e) 736 catch (SqlException e)
753 { 737 {
754 database.Reconnect();
755 m_log.Error(e.ToString()); 738 m_log.Error(e.ToString());
756 } 739 }
757 } 740 }
@@ -762,7 +745,7 @@ namespace OpenSim.Data.MSSQL
762 /// <param name="folderId">Id of folder to delete</param> 745 /// <param name="folderId">Id of folder to delete</param>
763 public void deleteInventoryFolder(LLUUID folderID) 746 public void deleteInventoryFolder(LLUUID folderID)
764 { 747 {
765 lock (database) 748 // lock (database)
766 { 749 {
767 List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID); 750 List<InventoryFolderBase> subFolders = getFolderHierarchy(folderID);
768 751