diff --git a/OpenSim/Data/MSSQL/AutoClosingSqlCommand.cs b/OpenSim/Data/MSSQL/AutoClosingSqlCommand.cs
new file mode 100644
index 0000000000..6a7d7875ac
--- /dev/null
+++ b/OpenSim/Data/MSSQL/AutoClosingSqlCommand.cs
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) Contributors, http://opensimulator.org/
+ * See CONTRIBUTORS.TXT for a full list of copyright holders.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of the OpenSim Project nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Data.SqlClient;
+using System.Data;
+
+namespace OpenSim.Data.MSSQL
+{
+ ///
+ /// Encapsulates a SqlCommand object but ensures that when it is disposed, its connection is closed and disposed also.
+ ///
+ internal class AutoClosingSqlCommand : IDbCommand
+ {
+ private SqlCommand realCommand;
+
+ public AutoClosingSqlCommand(SqlCommand cmd)
+ {
+ realCommand = cmd;
+ }
+
+ #region IDbCommand Members
+
+ public void Cancel()
+ {
+ realCommand.Cancel();
+ }
+
+ public string CommandText
+ {
+ get
+ {
+ return realCommand.CommandText;
+ }
+ set
+ {
+ realCommand.CommandText = value;
+ }
+ }
+
+ public int CommandTimeout
+ {
+ get
+ {
+ return realCommand.CommandTimeout;
+ }
+ set
+ {
+ realCommand.CommandTimeout = value;
+ }
+ }
+
+ public CommandType CommandType
+ {
+ get
+ {
+ return realCommand.CommandType;
+ }
+ set
+ {
+ realCommand.CommandType = value;
+ }
+ }
+
+ IDbConnection IDbCommand.Connection
+ {
+ get
+ {
+ return realCommand.Connection;
+ }
+ set
+ {
+ realCommand.Connection = (SqlConnection) value;
+ }
+ }
+
+ public SqlConnection Connection
+ {
+ get
+ {
+ return realCommand.Connection;
+ }
+ }
+
+ IDbDataParameter IDbCommand.CreateParameter()
+ {
+ return realCommand.CreateParameter();
+ }
+
+ public SqlParameter CreateParameter()
+ {
+ return realCommand.CreateParameter();
+ }
+
+ public int ExecuteNonQuery()
+ {
+ return realCommand.ExecuteNonQuery();
+ }
+
+ IDataReader IDbCommand.ExecuteReader(CommandBehavior behavior)
+ {
+ return realCommand.ExecuteReader(behavior);
+ }
+
+ public SqlDataReader ExecuteReader(CommandBehavior behavior)
+ {
+ return realCommand.ExecuteReader(behavior);
+ }
+
+ IDataReader IDbCommand.ExecuteReader()
+ {
+ return realCommand.ExecuteReader();
+ }
+
+ public SqlDataReader ExecuteReader()
+ {
+ return realCommand.ExecuteReader();
+ }
+
+ public object ExecuteScalar()
+ {
+ return realCommand.ExecuteScalar();
+ }
+
+ IDataParameterCollection IDbCommand.Parameters
+ {
+ get { return realCommand.Parameters; }
+ }
+
+ public SqlParameterCollection Parameters
+ {
+ get { return realCommand.Parameters; }
+ }
+
+ public void Prepare()
+ {
+ realCommand.Prepare();
+ }
+
+ IDbTransaction IDbCommand.Transaction
+ {
+ get
+ {
+ return realCommand.Transaction;
+ }
+ set
+ {
+ realCommand.Transaction = (SqlTransaction) value;
+ }
+ }
+
+ UpdateRowSource IDbCommand.UpdatedRowSource
+ {
+ get
+ {
+ return realCommand.UpdatedRowSource;
+ }
+ set
+ {
+ realCommand.UpdatedRowSource = value;
+ }
+ }
+
+ #endregion
+
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ SqlConnection conn = realCommand.Connection;
+ try
+ {
+ realCommand.Dispose();
+ }
+ finally
+ {
+ try
+ {
+ conn.Close();
+ }
+ finally
+ {
+ conn.Dispose();
+ }
+ }
+ }
+
+ #endregion
+ }
+}
diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
index 108ceb19ee..e0e20dfa9e 100644
--- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
@@ -86,19 +86,14 @@ namespace OpenSim.Data.MSSQL
///
override public AssetBase FetchAsset(LLUUID assetID)
{
- AssetBase asset = null;
-
Dictionary param = new Dictionary();
param["id"] = assetID.ToString();
- IDbCommand result = database.Query("SELECT * FROM assets WHERE id = @id", param);
- IDataReader reader = result.ExecuteReader();
-
- asset = database.getAssetRow(reader);
- reader.Close();
- result.Dispose();
-
- return asset;
+ using (IDbCommand result = database.Query("SELECT * FROM assets WHERE id = @id", param))
+ using (IDataReader reader = result.ExecuteReader())
+ {
+ return database.getAssetRow(reader);
+ }
}
///
@@ -113,15 +108,13 @@ namespace OpenSim.Data.MSSQL
}
- SqlCommand cmd =
- new SqlCommand(
+ using (AutoClosingSqlCommand cmd =
+ database.Query(
"INSERT INTO assets ([id], [name], [description], [assetType], [local], [temporary], [data])" +
" VALUES " +
- "(@id, @name, @description, @assetType, @local, @temporary, @data)",
- database.getConnection());
-
- using (cmd)
+ "(@id, @name, @description, @assetType, @local, @temporary, @data)"))
{
+
//SqlParameter p = cmd.Parameters.Add("id", SqlDbType.NVarChar);
//p.Value = asset.FullID.ToString();
cmd.Parameters.AddWithValue("id", asset.FullID.ToString());
@@ -135,16 +128,8 @@ namespace OpenSim.Data.MSSQL
h.Value = asset.Temporary;
SqlParameter i = cmd.Parameters.Add("data", SqlDbType.Image);
i.Value = asset.Data;
- try
- {
- cmd.ExecuteNonQuery();
- }
- catch (Exception)
- {
- throw;
- }
- cmd.Dispose();
+ cmd.ExecuteNonQuery();
}
}
@@ -154,38 +139,40 @@ namespace OpenSim.Data.MSSQL
/// the asset
override public void UpdateAsset(AssetBase asset)
{
- SqlCommand command = new SqlCommand("UPDATE assets set id = @id, " +
+ using (IDbCommand command = database.Query("UPDATE assets set id = @id, " +
"name = @name, " +
"description = @description," +
"assetType = @assetType," +
"local = @local," +
"temporary = @temporary," +
"data = @data where " +
- "id = @keyId;", database.getConnection());
- SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToString());
- SqlParameter param2 = new SqlParameter("@name", asset.Name);
- SqlParameter param3 = new SqlParameter("@description", asset.Description);
- SqlParameter param4 = new SqlParameter("@assetType", asset.Type);
- SqlParameter param6 = new SqlParameter("@local", asset.Local);
- SqlParameter param7 = new SqlParameter("@temporary", asset.Temporary);
- SqlParameter param8 = new SqlParameter("@data", asset.Data);
- SqlParameter param9 = new SqlParameter("@keyId", asset.FullID.ToString());
- command.Parameters.Add(param1);
- command.Parameters.Add(param2);
- command.Parameters.Add(param3);
- command.Parameters.Add(param4);
- command.Parameters.Add(param6);
- command.Parameters.Add(param7);
- command.Parameters.Add(param8);
- command.Parameters.Add(param9);
+ "id = @keyId;"))
+ {
+ SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToString());
+ SqlParameter param2 = new SqlParameter("@name", asset.Name);
+ SqlParameter param3 = new SqlParameter("@description", asset.Description);
+ SqlParameter param4 = new SqlParameter("@assetType", asset.Type);
+ SqlParameter param6 = new SqlParameter("@local", asset.Local);
+ SqlParameter param7 = new SqlParameter("@temporary", asset.Temporary);
+ SqlParameter param8 = new SqlParameter("@data", asset.Data);
+ SqlParameter param9 = new SqlParameter("@keyId", asset.FullID.ToString());
+ command.Parameters.Add(param1);
+ command.Parameters.Add(param2);
+ command.Parameters.Add(param3);
+ command.Parameters.Add(param4);
+ command.Parameters.Add(param6);
+ command.Parameters.Add(param7);
+ command.Parameters.Add(param8);
+ command.Parameters.Add(param9);
- try
- {
- command.ExecuteNonQuery();
- }
- catch (Exception e)
- {
- m_log.Error(e.ToString());
+ try
+ {
+ command.ExecuteNonQuery();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ }
}
}
@@ -228,12 +215,12 @@ namespace OpenSim.Data.MSSQL
/// it use mssql_connection.ini
override public void Initialise()
{
- IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
- string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
- string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
- string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
- string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
- string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
+ IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
+ string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
+ string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
+ string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
+ string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
+ string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
diff --git a/OpenSim/Data/MSSQL/MSSQLDataStore.cs b/OpenSim/Data/MSSQL/MSSQLDataStore.cs
index d9d41e0f9b..46e410765d 100644
--- a/OpenSim/Data/MSSQL/MSSQLDataStore.cs
+++ b/OpenSim/Data/MSSQL/MSSQLDataStore.cs
@@ -1758,7 +1758,7 @@ namespace OpenSim.Data.MSSQL
}
catch (SqlException)
{
- m_log.Info("[REGION DB]: MySql Database doesn't exist... creating");
+ m_log.Info("[REGION DB]: MS Sql Database doesn't exist... creating");
InitDB(conn);
}
diff --git a/OpenSim/Data/MSSQL/MSSQLGridData.cs b/OpenSim/Data/MSSQL/MSSQLGridData.cs
index 1ed412bdc8..0abd0d039d 100644
--- a/OpenSim/Data/MSSQL/MSSQLGridData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLGridData.cs
@@ -84,17 +84,17 @@ namespace OpenSim.Data.MSSQL
///
private void TestTables()
{
- IDbCommand cmd = database.Query("SELECT TOP 1 * FROM "+m_regionsTableName, new Dictionary());
-
- try
+ using (IDbCommand cmd = database.Query("SELECT TOP 1 * FROM " + m_regionsTableName, new Dictionary()))
{
- cmd.ExecuteNonQuery();
- cmd.Dispose();
- }
- catch (Exception)
- {
- m_log.Info("[GRID DB]: MSSQL Database doesn't exist... creating");
- database.ExecuteResourceSql("Mssql-regions.sql");
+ try
+ {
+ cmd.ExecuteNonQuery();
+ }
+ catch (Exception)
+ {
+ m_log.Info("[GRID DB]: MSSQL Database doesn't exist... creating");
+ database.ExecuteResourceSql("Mssql-regions.sql");
+ }
}
}
@@ -103,7 +103,7 @@ namespace OpenSim.Data.MSSQL
///
override public void Close()
{
- database.Close();
+ // nothing to close
}
///
@@ -146,32 +146,22 @@ namespace OpenSim.Data.MSSQL
/// Sim profile
override public RegionProfileData GetProfileByHandle(ulong handle)
{
- IDataReader reader = null;
+
+ Dictionary param = new Dictionary();
+ param["handle"] = handle.ToString();
+
try
{
- if (database.getConnection().State == ConnectionState.Closed)
+ using (IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- database.Reconnect();
+ return database.getRegionRow(reader);
}
- Dictionary param = new Dictionary();
- param["handle"] = handle.ToString();
- IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE regionHandle = @handle", param);
- reader = result.ExecuteReader();
-
- RegionProfileData row = database.getRegionRow(reader);
- reader.Close();
- result.Dispose();
-
- return row;
}
- catch (Exception)
+ catch
{
- if (reader != null)
- {
- reader.Close();
- }
+ return null;
}
- return null;
}
///
@@ -183,14 +173,13 @@ namespace OpenSim.Data.MSSQL
{
Dictionary param = new Dictionary();
param["uuid"] = uuid.ToString();
- IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid", param);
- IDataReader reader = result.ExecuteReader();
- RegionProfileData row = database.getRegionRow(reader);
- reader.Close();
- result.Dispose();
+ using (IDbCommand result = database.Query("SELECT * FROM " + m_regionsTableName + " WHERE uuid = @uuid", param))
+ using (IDataReader reader = result.ExecuteReader())
+ {
+ return database.getRegionRow(reader);
+ }
- return row;
}
///
@@ -204,25 +193,19 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
+ Dictionary param = new Dictionary();
+ // Add % because this is a like query.
+ param["?regionName"] = regionName + "%";
+ // Order by statement will return shorter matches first. Only returns one record or no record.
+ using (IDbCommand result = database.Query("SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like ?regionName order by regionName", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- Dictionary param = new Dictionary();
- // Add % because this is a like query.
- param["?regionName"] = regionName + "%";
- // Order by statement will return shorter matches first. Only returns one record or no record.
- IDbCommand result = database.Query("SELECT top 1 * FROM " + m_regionsTableName + " WHERE regionName like ?regionName order by regionName", param);
- IDataReader reader = result.ExecuteReader();
-
- RegionProfileData row = database.getRegionRow(reader);
- reader.Close();
- result.Dispose();
-
- return row;
+ return database.getRegionRow(reader);
}
+
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -324,12 +307,13 @@ namespace OpenSim.Data.MSSQL
try
{
- IDbCommand result = database.Query(sql, parameters);
+ using (IDbCommand result = database.Query(sql, parameters))
+ {
- if (result.ExecuteNonQuery() == 1)
- returnval = true;
+ if (result.ExecuteNonQuery() == 1)
+ returnval = true;
- result.Dispose();
+ }
}
catch (Exception e)
{
@@ -347,17 +331,15 @@ namespace OpenSim.Data.MSSQL
{
//Insert new region
string sql =
- "INSERT INTO " + m_regionsTableName + " ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI], ";
- sql +=
- "[serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle], [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], ";
- sql +=
- "[regionAssetSendKey], [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort], [serverRemotingPort], [owner_uuid]) VALUES ";
-
- sql += "(@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI, ";
- sql +=
- "@serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle, @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, ";
- sql +=
- "@regionAssetSendKey, @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid);";
+ "INSERT INTO " + m_regionsTableName + @" ([regionHandle], [regionName], [uuid], [regionRecvKey], [regionSecret], [regionSendKey], [regionDataURI],
+ [serverIP], [serverPort], [serverURI], [locX], [locY], [locZ], [eastOverrideHandle], [westOverrideHandle],
+ [southOverrideHandle], [northOverrideHandle], [regionAssetURI], [regionAssetRecvKey], [regionAssetSendKey],
+ [regionUserURI], [regionUserRecvKey], [regionUserSendKey], [regionMapTexture], [serverHttpPort],
+ [serverRemotingPort], [owner_uuid])
+ VALUES (@regionHandle, @regionName, @uuid, @regionRecvKey, @regionSecret, @regionSendKey, @regionDataURI,
+ @serverIP, @serverPort, @serverURI, @locX, @locY, @locZ, @eastOverrideHandle, @westOverrideHandle,
+ @southOverrideHandle, @northOverrideHandle, @regionAssetURI, @regionAssetRecvKey, @regionAssetSendKey,
+ @regionUserURI, @regionUserRecvKey, @regionUserSendKey, @regionMapTexture, @serverHttpPort, @serverRemotingPort, @owner_uuid);";
Dictionary parameters = new Dictionary();
@@ -393,12 +375,11 @@ namespace OpenSim.Data.MSSQL
try
{
- IDbCommand result = database.Query(sql, parameters);
-
- if (result.ExecuteNonQuery() == 1)
- returnval = true;
-
- result.Dispose();
+ using (IDbCommand result = database.Query(sql, parameters))
+ {
+ if (result.ExecuteNonQuery() == 1)
+ returnval = true;
+ }
}
catch (Exception e)
{
diff --git a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
index 3177325080..4a8d6e9b3a 100644
--- a/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLInventoryData.cs
@@ -67,12 +67,12 @@ namespace OpenSim.Data.MSSQL
public void Initialise(string connect)
{
// TODO: actually use the provided connect string
- IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
- string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
- string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
- string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
- string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
- string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
+ IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
+ string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
+ string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
+ string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
+ string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
+ string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
@@ -165,29 +165,26 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
+ List items = new List();
+
+ Dictionary param = new Dictionary();
+ param["parentFolderID"] = folderID.ToString();
+
+ using (IDbCommand result =
+ database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- List items = new List();
-
- Dictionary param = new Dictionary();
- param["parentFolderID"] = folderID.ToString();
-
- IDbCommand result =
- database.Query("SELECT * FROM inventoryitems WHERE parentFolderID = @parentFolderID", param);
- IDataReader reader = result.ExecuteReader();
while (reader.Read())
items.Add(readInventoryItem(reader));
reader.Close();
- result.Dispose();
-
- return items;
}
+
+ return items;
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -202,30 +199,26 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
- {
- Dictionary param = new Dictionary();
- param["uuid"] = user.ToString();
- param["zero"] = LLUUID.Zero.ToString();
+ Dictionary param = new Dictionary();
+ param["uuid"] = user.ToString();
+ param["zero"] = LLUUID.Zero.ToString();
- IDbCommand result =
- database.Query(
- "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param);
- IDataReader reader = result.ExecuteReader();
+ using (IDbCommand result =
+ database.Query(
+ "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param))
+ using (IDataReader reader = result.ExecuteReader())
+ {
List items = new List();
while (reader.Read())
items.Add(readInventoryFolder(reader));
- reader.Close();
- result.Dispose();
-
return items;
}
+
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -240,16 +233,15 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
- {
- Dictionary param = new Dictionary();
- param["uuid"] = user.ToString();
- param["zero"] = LLUUID.Zero.ToString();
+ Dictionary param = new Dictionary();
+ param["uuid"] = user.ToString();
+ param["zero"] = LLUUID.Zero.ToString();
- IDbCommand result =
- database.Query(
- "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param);
- IDataReader reader = result.ExecuteReader();
+ using (IDbCommand result =
+ database.Query(
+ "SELECT * FROM inventoryfolders WHERE parentFolderID = @zero AND agentID = @uuid", param))
+ using (IDataReader reader = result.ExecuteReader())
+ {
List items = new List();
while (reader.Read())
@@ -267,15 +259,12 @@ namespace OpenSim.Data.MSSQL
rootFolder = items[0];
}
- reader.Close();
- result.Dispose();
-
return rootFolder;
}
+
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -290,30 +279,23 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
+ Dictionary param = new Dictionary();
+ param["parentFolderID"] = parentID.ToString();
+
+ using (IDbCommand result =
+ database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- Dictionary param = new Dictionary();
- param["parentFolderID"] = parentID.ToString();
-
-
- IDbCommand result =
- database.Query("SELECT * FROM inventoryfolders WHERE parentFolderID = @parentFolderID", param);
- IDataReader reader = result.ExecuteReader();
-
List items = new List();
while (reader.Read())
items.Add(readInventoryFolder(reader));
- reader.Close();
- result.Dispose();
-
return items;
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -369,28 +351,23 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
- {
- Dictionary param = new Dictionary();
- param["inventoryID"] = itemID.ToString();
+ Dictionary param = new Dictionary();
+ param["inventoryID"] = itemID.ToString();
- IDbCommand result =
- database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param);
- IDataReader reader = result.ExecuteReader();
+ using (IDbCommand result =
+ database.Query("SELECT * FROM inventoryitems WHERE inventoryID = @inventoryID", param))
+ using (IDataReader reader = result.ExecuteReader())
+ {
InventoryItemBase item = null;
if (reader.Read())
item = readInventoryItem(reader);
- reader.Close();
- result.Dispose();
-
return item;
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
}
return null;
@@ -431,25 +408,22 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
- {
- Dictionary param = new Dictionary();
- param["uuid"] = folderID.ToString();
+ Dictionary param = new Dictionary();
+ param["uuid"] = folderID.ToString();
- IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param);
- IDataReader reader = result.ExecuteReader();
+ using (IDbCommand result = database.Query("SELECT * FROM inventoryfolders WHERE folderID = @uuid", param))
+ using (IDataReader reader = result.ExecuteReader())
+ {
reader.Read();
+
InventoryFolderBase folder = readInventoryFolder(reader);
- reader.Close();
- result.Dispose();
return folder;
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -479,9 +453,8 @@ namespace OpenSim.Data.MSSQL
+ ", @inventoryBasePermissions, @inventoryEveryOnePermissions, @salePrice, @saleType"
+ ", @creationDate, @groupID, @groupOwned, @flags);";
- try
+ using (AutoClosingSqlCommand command = database.Query(sql))
{
- SqlCommand command = new SqlCommand(sql, database.getConnection());
command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
@@ -502,13 +475,16 @@ namespace OpenSim.Data.MSSQL
command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
- command.ExecuteNonQuery();
- command.Dispose();
- }
- catch (SqlException e)
- {
- m_log.Error(e.ToString());
+ try
+ {
+ command.ExecuteNonQuery();
+ }
+ catch (SqlException e)
+ {
+ m_log.Error(e.ToString());
+ }
}
+
}
///
@@ -517,7 +493,7 @@ namespace OpenSim.Data.MSSQL
/// Inventory item to update
public void updateInventoryItem(InventoryItemBase item)
{
- SqlCommand command = new SqlCommand("UPDATE inventoryitems set inventoryID = @inventoryID, " +
+ using (AutoClosingSqlCommand command = database.Query("UPDATE inventoryitems set inventoryID = @inventoryID, " +
"assetID = @assetID, " +
"assetType = @assetType," +
"parentFolderID = @parentFolderID," +
@@ -529,42 +505,44 @@ namespace OpenSim.Data.MSSQL
"invType = @invType," +
"creatorID = @creatorID," +
"inventoryBasePermissions = @inventoryBasePermissions," +
- "inventoryEveryOnePermissions = @inventoryEveryOnePermissions," +
+ "inventoryEveryOnePermissions = @inventoryEveryOnePermissions," +
"salePrice = @salePrice," +
- "saleType = @saleType," +
+ "saleType = @saleType," +
"creationDate = @creationDate," +
- "groupID = @groupID," +
- "groupOwned = @groupOwned," +
+ "groupID = @groupID," +
+ "groupOwned = @groupOwned," +
"flags = @flags where " +
- "inventoryID = @keyInventoryID;", database.getConnection());
- command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
- command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
- command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
- command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
- command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
- command.Parameters.AddWithValue("inventoryName", item.Name);
- command.Parameters.AddWithValue("inventoryDescription", item.Description);
- command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
- command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
- command.Parameters.AddWithValue("invType", item.InvType);
- command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
- command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
- command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
- command.Parameters.AddWithValue("salePrice", item.SalePrice);
- command.Parameters.AddWithValue("saleType", item.SaleType);
- command.Parameters.AddWithValue("creationDate", item.CreationDate);
- command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
- command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
- command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
- command.Parameters.AddWithValue("@keyInventoryID", item.ID.ToString());
+ "inventoryID = @keyInventoryID;"))
+ {
+ command.Parameters.AddWithValue("inventoryID", item.ID.ToString());
+ command.Parameters.AddWithValue("assetID", item.AssetID.ToString());
+ command.Parameters.AddWithValue("assetType", item.AssetType.ToString());
+ command.Parameters.AddWithValue("parentFolderID", item.Folder.ToString());
+ command.Parameters.AddWithValue("avatarID", item.Owner.ToString());
+ command.Parameters.AddWithValue("inventoryName", item.Name);
+ command.Parameters.AddWithValue("inventoryDescription", item.Description);
+ command.Parameters.AddWithValue("inventoryNextPermissions", ConvertUint32BitFieldToInt32(item.NextPermissions));
+ command.Parameters.AddWithValue("inventoryCurrentPermissions", ConvertUint32BitFieldToInt32(item.CurrentPermissions));
+ command.Parameters.AddWithValue("invType", item.InvType);
+ command.Parameters.AddWithValue("creatorID", item.Creator.ToString());
+ command.Parameters.AddWithValue("inventoryBasePermissions", ConvertUint32BitFieldToInt32(item.BasePermissions));
+ command.Parameters.AddWithValue("inventoryEveryOnePermissions", ConvertUint32BitFieldToInt32(item.EveryOnePermissions));
+ command.Parameters.AddWithValue("salePrice", item.SalePrice);
+ command.Parameters.AddWithValue("saleType", item.SaleType);
+ command.Parameters.AddWithValue("creationDate", item.CreationDate);
+ command.Parameters.AddWithValue("groupID", item.GroupID.ToString());
+ command.Parameters.AddWithValue("groupOwned", item.GroupOwned);
+ command.Parameters.AddWithValue("flags", ConvertUint32BitFieldToInt32(item.Flags));
+ command.Parameters.AddWithValue("@keyInventoryID", item.ID.ToString());
- try
- {
- command.ExecuteNonQuery();
- }
- catch (Exception e)
- {
- m_log.Error(e.ToString());
+ try
+ {
+ command.ExecuteNonQuery();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ }
}
}
@@ -579,13 +557,13 @@ namespace OpenSim.Data.MSSQL
Dictionary param = new Dictionary();
param["uuid"] = itemID.ToString();
- IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param);
- cmd.ExecuteNonQuery();
- cmd.Dispose();
+ using (IDbCommand cmd = database.Query("DELETE FROM inventoryitems WHERE inventoryID=@uuid", param))
+ {
+ cmd.ExecuteNonQuery();
+ }
}
catch (SqlException e)
{
- database.Reconnect();
m_log.Error(e.ToString());
}
}
@@ -601,23 +579,24 @@ namespace OpenSim.Data.MSSQL
sql += "(@folderID, @agentID, @parentFolderID, @folderName, @type, @version);";
- SqlCommand command = new SqlCommand(sql, database.getConnection());
- command.Parameters.AddWithValue("folderID", folder.ID.ToString());
- command.Parameters.AddWithValue("agentID", folder.Owner.ToString());
- command.Parameters.AddWithValue("parentFolderID", folder.ParentID.ToString());
- command.Parameters.AddWithValue("folderName", folder.Name);
- command.Parameters.AddWithValue("type", folder.Type);
- command.Parameters.AddWithValue("version", Convert.ToInt32(folder.Version));
+ using (AutoClosingSqlCommand command = database.Query(sql))
+ {
+ command.Parameters.AddWithValue("folderID", folder.ID.ToString());
+ command.Parameters.AddWithValue("agentID", folder.Owner.ToString());
+ command.Parameters.AddWithValue("parentFolderID", folder.ParentID.ToString());
+ command.Parameters.AddWithValue("folderName", folder.Name);
+ command.Parameters.AddWithValue("type", folder.Type);
+ command.Parameters.AddWithValue("version", Convert.ToInt32(folder.Version));
- try
- {
- //IDbCommand result = database.Query(sql, param);
- command.ExecuteNonQuery();
- command.Dispose();
- }
- catch (Exception e)
- {
- m_log.Error(e.ToString());
+ try
+ {
+ //IDbCommand result = database.Query(sql, param);
+ command.ExecuteNonQuery();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ }
}
}
@@ -627,35 +606,37 @@ namespace OpenSim.Data.MSSQL
/// Folder to update
public void updateInventoryFolder(InventoryFolderBase folder)
{
- SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " +
+ using (IDbCommand command = database.Query("UPDATE inventoryfolders set folderID = @folderID, " +
"agentID = @agentID, " +
"parentFolderID = @parentFolderID," +
"folderName = @folderName," +
"type = @type," +
"version = @version where " +
- "folderID = @keyFolderID;", database.getConnection());
- SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString());
- SqlParameter param2 = new SqlParameter("@agentID", folder.Owner.ToString());
- SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
- SqlParameter param4 = new SqlParameter("@folderName", folder.Name);
- SqlParameter param5 = new SqlParameter("@type", folder.Type);
- SqlParameter param6 = new SqlParameter("@version", Convert.ToInt32(folder.Version));
- SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString());
- command.Parameters.Add(param1);
- command.Parameters.Add(param2);
- command.Parameters.Add(param3);
- command.Parameters.Add(param4);
- command.Parameters.Add(param5);
- command.Parameters.Add(param6);
- command.Parameters.Add(param7);
+ "folderID = @keyFolderID;"))
+ {
+ SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString());
+ SqlParameter param2 = new SqlParameter("@agentID", folder.Owner.ToString());
+ SqlParameter param3 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
+ SqlParameter param4 = new SqlParameter("@folderName", folder.Name);
+ SqlParameter param5 = new SqlParameter("@type", folder.Type);
+ SqlParameter param6 = new SqlParameter("@version", Convert.ToInt32(folder.Version));
+ SqlParameter param7 = new SqlParameter("@keyFolderID", folder.ID.ToString());
+ command.Parameters.Add(param1);
+ command.Parameters.Add(param2);
+ command.Parameters.Add(param3);
+ command.Parameters.Add(param4);
+ command.Parameters.Add(param5);
+ command.Parameters.Add(param6);
+ command.Parameters.Add(param7);
- try
- {
- command.ExecuteNonQuery();
- }
- catch (Exception e)
- {
- m_log.Error(e.ToString());
+ try
+ {
+ command.ExecuteNonQuery();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ }
}
}
@@ -665,23 +646,25 @@ namespace OpenSim.Data.MSSQL
/// Folder to update
public void moveInventoryFolder(InventoryFolderBase folder)
{
- SqlCommand command = new SqlCommand("UPDATE inventoryfolders set folderID = @folderID, " +
+ using (IDbCommand command = database.Query("UPDATE inventoryfolders set folderID = @folderID, " +
"parentFolderID = @parentFolderID," +
- "folderID = @keyFolderID;", database.getConnection());
- SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString());
- SqlParameter param2 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
- SqlParameter param3 = new SqlParameter("@keyFolderID", folder.ID.ToString());
- command.Parameters.Add(param1);
- command.Parameters.Add(param2);
- command.Parameters.Add(param3);
+ "folderID = @keyFolderID;"))
+ {
+ SqlParameter param1 = new SqlParameter("@folderID", folder.ID.ToString());
+ SqlParameter param2 = new SqlParameter("@parentFolderID", folder.ParentID.ToString());
+ SqlParameter param3 = new SqlParameter("@keyFolderID", folder.ID.ToString());
+ command.Parameters.Add(param1);
+ command.Parameters.Add(param2);
+ command.Parameters.Add(param3);
- try
- {
- command.ExecuteNonQuery();
- }
- catch (Exception e)
- {
- m_log.Error(e.ToString());
+ try
+ {
+ command.ExecuteNonQuery();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ }
}
}
@@ -721,13 +704,13 @@ namespace OpenSim.Data.MSSQL
Dictionary param = new Dictionary();
param["folderID"] = folderID.ToString();
- IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param);
- cmd.ExecuteNonQuery();
- cmd.Dispose();
+ using (IDbCommand cmd = database.Query("DELETE FROM inventoryfolders WHERE folderID=@folderID", param))
+ {
+ cmd.ExecuteNonQuery();
+ }
}
catch (SqlException e)
{
- database.Reconnect();
m_log.Error(e.ToString());
}
}
@@ -744,14 +727,14 @@ namespace OpenSim.Data.MSSQL
param["parentFolderID"] = folderID.ToString();
- IDbCommand cmd =
- database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param);
- cmd.ExecuteNonQuery();
- cmd.Dispose();
+ using (IDbCommand cmd =
+ database.Query("DELETE FROM inventoryitems WHERE parentFolderID=@parentFolderID", param))
+ {
+ cmd.ExecuteNonQuery();
+ }
}
catch (SqlException e)
{
- database.Reconnect();
m_log.Error(e.ToString());
}
}
@@ -762,7 +745,7 @@ namespace OpenSim.Data.MSSQL
/// Id of folder to delete
public void deleteInventoryFolder(LLUUID folderID)
{
- lock (database)
+ // lock (database)
{
List subFolders = getFolderHierarchy(folderID);
diff --git a/OpenSim/Data/MSSQL/MSSQLLogData.cs b/OpenSim/Data/MSSQL/MSSQLLogData.cs
index c75290e798..849d0fbbe8 100644
--- a/OpenSim/Data/MSSQL/MSSQLLogData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLLogData.cs
@@ -31,7 +31,7 @@ using System.Data;
namespace OpenSim.Data.MSSQL
{
///
- /// An interface to the log database for MySQL
+ /// An interface to the log database for MSSQL
///
internal class MSSQLLogData : ILogData
{
@@ -46,26 +46,27 @@ namespace OpenSim.Data.MSSQL
public void Initialise(string connect)
{
// TODO: do something with the connect string
- IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini");
- string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source");
- string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog");
- string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info");
- string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id");
- string settingPassword = GridDataMySqlFile.ParseFileReadValue("password");
+ IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
+ string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
+ string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
+ string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
+ string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
+ string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
database =
new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,
settingPassword);
- IDbCommand cmd = database.Query("select top 1 * from logs", new Dictionary());
- try
+ using (IDbCommand cmd = database.Query("select top 1 * from logs", new Dictionary()))
{
- cmd.ExecuteNonQuery();
- cmd.Dispose();
- }
- catch
- {
- database.ExecuteResourceSql("Mssql-logs.sql");
+ try
+ {
+ cmd.ExecuteNonQuery();
+ }
+ catch
+ {
+ database.ExecuteResourceSql("Mssql-logs.sql");
+ }
}
}
@@ -88,7 +89,7 @@ namespace OpenSim.Data.MSSQL
}
catch
{
- database.Reconnect();
+ // it didn't log, don't worry about it
}
}
diff --git a/OpenSim/Data/MSSQL/MSSQLManager.cs b/OpenSim/Data/MSSQL/MSSQLManager.cs
index e421c5d4e3..fe4ca77d80 100644
--- a/OpenSim/Data/MSSQL/MSSQLManager.cs
+++ b/OpenSim/Data/MSSQL/MSSQLManager.cs
@@ -44,11 +44,6 @@ namespace OpenSim.Data.MSSQL
{
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- ///
- /// The database connection object
- ///
- private IDbConnection dbcon;
-
///
/// Connection string for ADO.net
///
@@ -57,11 +52,24 @@ namespace OpenSim.Data.MSSQL
public MSSQLManager(string dataSource, string initialCatalog, string persistSecurityInfo, string userId,
string password)
{
- connectionString = "Data Source=" + dataSource + ";Initial Catalog=" + initialCatalog +
- ";Persist Security Info=" + persistSecurityInfo + ";User ID=" + userId + ";Password=" +
- password + ";";
- dbcon = new SqlConnection(connectionString);
- dbcon.Open();
+ SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
+
+ builder.DataSource = dataSource;
+ builder.InitialCatalog = initialCatalog;
+ builder.PersistSecurityInfo = Convert.ToBoolean(persistSecurityInfo);
+ builder.UserID = userId;
+ builder.Password = password;
+ builder.ApplicationName = Assembly.GetEntryAssembly().Location;
+
+ connectionString = builder.ToString();
+ }
+
+ private SqlConnection createConnection()
+ {
+ SqlConnection conn = new SqlConnection(connectionString);
+ conn.Open();
+
+ return conn;
}
//private DataTable createRegionsTable()
@@ -121,7 +129,7 @@ namespace OpenSim.Data.MSSQL
}
///
- ///
+ /// Define Table function
///
///
///
@@ -178,35 +186,11 @@ namespace OpenSim.Data.MSSQL
}
}
- ///
- /// Shuts down the database connection
- ///
- public void Close()
- {
- dbcon.Close();
- dbcon = null;
- }
- ///
- /// Reconnects to the database
- ///
- public void Reconnect()
+ private static readonly Dictionary emptyDictionary = new Dictionary();
+ internal AutoClosingSqlCommand Query(string sql)
{
- lock (dbcon)
- {
- try
- {
- // Close the DB connection
- dbcon.Close();
- // Try reopen it
- dbcon = new SqlConnection(connectionString);
- dbcon.Open();
- }
- catch (Exception e)
- {
- m_log.Error("Unable to reconnect to database " + e.ToString());
- }
- }
+ return Query(sql, emptyDictionary);
}
///
@@ -215,18 +199,20 @@ namespace OpenSim.Data.MSSQL
/// The SQL string - replace any variables such as WHERE x = "y" with WHERE x = @y
/// The parameters - index so that @y is indexed as 'y'
/// A Sql DB Command
- public IDbCommand Query(string sql, Dictionary parameters)
+ internal AutoClosingSqlCommand Query(string sql, Dictionary parameters)
{
- SqlCommand dbcommand = (SqlCommand)dbcon.CreateCommand();
+ SqlCommand dbcommand = createConnection().CreateCommand();
dbcommand.CommandText = sql;
foreach (KeyValuePair param in parameters)
{
dbcommand.Parameters.AddWithValue(param.Key, param.Value);
}
- return (IDbCommand)dbcommand;
+ return new AutoClosingSqlCommand(dbcommand);
}
+
+
///
/// Runs a database reader object and returns a region row
///
@@ -400,7 +386,6 @@ namespace OpenSim.Data.MSSQL
if (reader.Read())
{
// Region Main
-
asset = new AssetBase();
asset.Data = (byte[])reader["data"];
asset.Description = (string)reader["description"];
@@ -443,19 +428,20 @@ namespace OpenSim.Data.MSSQL
bool returnval = false;
- try
+ using (IDbCommand result = Query(sql, parameters))
{
- IDbCommand result = Query(sql, parameters);
+ try
+ {
- if (result.ExecuteNonQuery() == 1)
- returnval = true;
+ if (result.ExecuteNonQuery() == 1)
+ returnval = true;
- result.Dispose();
- }
- catch (Exception e)
- {
- m_log.Error(e.ToString());
- return false;
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ return false;
+ }
}
return returnval;
@@ -467,19 +453,12 @@ namespace OpenSim.Data.MSSQL
/// the ressource string
public void ExecuteResourceSql(string name)
{
- SqlCommand cmd = new SqlCommand(getResourceString(name), (SqlConnection)dbcon);
- cmd.ExecuteNonQuery();
- cmd.Dispose();
+ using (IDbCommand cmd = Query(getResourceString(name), new Dictionary()))
+ {
+ cmd.ExecuteNonQuery();
+ }
}
- ///
- ///
- ///
- /// The actual SqlConnection
- public SqlConnection getConnection()
- {
- return (SqlConnection)dbcon;
- }
///
/// Given a list of tables, return the version of the tables, as seen in the database
@@ -487,30 +466,29 @@ namespace OpenSim.Data.MSSQL
///
public void GetTableVersion(Dictionary tableList)
{
- lock (dbcon)
+ Dictionary param = new Dictionary();
+ param["dbname"] = new SqlConnectionStringBuilder(connectionString).InitialCatalog;
+
+ using (IDbCommand tablesCmd =
+ Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG=@dbname", param))
+ using (IDataReader tables = tablesCmd.ExecuteReader())
{
- Dictionary param = new Dictionary();
- param["dbname"] = dbcon.Database;
- IDbCommand tablesCmd =
- Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_CATALOG=@dbname", param);
- using (IDataReader tables = tablesCmd.ExecuteReader())
+ while (tables.Read())
{
- while (tables.Read())
+ try
{
- try
- {
- string tableName = (string)tables["TABLE_NAME"];
- if (tableList.ContainsKey(tableName))
- tableList[tableName] = tableName;
- }
- catch (Exception e)
- {
- m_log.Error(e.ToString());
- }
+ string tableName = (string)tables["TABLE_NAME"];
+ if (tableList.ContainsKey(tableName))
+ tableList[tableName] = tableName;
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
}
- tables.Close();
}
+ tables.Close();
}
+
}
///
@@ -546,7 +524,6 @@ namespace OpenSim.Data.MSSQL
// string dllName = module.Assembly.ManifestModule.Name;
Version dllVersion = module.Assembly.GetName().Version;
-
return
string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build,
dllVersion.Revision);
diff --git a/OpenSim/Data/MSSQL/MSSQLUserData.cs b/OpenSim/Data/MSSQL/MSSQLUserData.cs
index cb5ba241ee..20c3acd966 100644
--- a/OpenSim/Data/MSSQL/MSSQLUserData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLUserData.cs
@@ -44,7 +44,7 @@ namespace OpenSim.Data.MSSQL
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
///
- /// Database manager for MySQL
+ /// Database manager for MSSQL
///
public MSSQLManager database;
@@ -100,36 +100,41 @@ namespace OpenSim.Data.MSSQL
///
private bool TestTables()
{
- IDbCommand cmd;
- cmd = database.Query("select top 1 * from " + m_usersTableName, new Dictionary());
- try
+ using (IDbCommand cmd = database.Query("select top 1 * from " + m_usersTableName, new Dictionary()))
{
- cmd.ExecuteNonQuery();
- }
- catch
- {
- database.ExecuteResourceSql("Mssql-users.sql");
+ try
+ {
+ cmd.ExecuteNonQuery();
+ }
+ catch
+ {
+ database.ExecuteResourceSql("Mssql-users.sql");
+ }
}
- cmd = database.Query("select top 1 * from " + m_agentsTableName, new Dictionary());
- try
+ using (IDbCommand cmd = database.Query("select top 1 * from " + m_agentsTableName, new Dictionary()))
{
- cmd.ExecuteNonQuery();
- }
- catch
- {
- database.ExecuteResourceSql("Mssql-agents.sql");
+ try
+ {
+ cmd.ExecuteNonQuery();
+ }
+ catch
+ {
+ database.ExecuteResourceSql("Mssql-agents.sql");
+ }
}
- cmd = database.Query("select top 1 * from " + m_userFriendsTableName, new Dictionary());
- try
+ using (IDbCommand cmd = database.Query("select top 1 * from " + m_userFriendsTableName, new Dictionary()))
{
- cmd.ExecuteNonQuery();
- }
- catch
- {
- database.ExecuteResourceSql("CreateUserFriendsTable.sql");
+ try
+ {
+ cmd.ExecuteNonQuery();
+ }
+ catch
+ {
+ database.ExecuteResourceSql("CreateUserFriendsTable.sql");
+ }
}
return true;
@@ -145,27 +150,18 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
+ Dictionary param = new Dictionary();
+ param["first"] = user;
+ param["second"] = last;
+
+ using (IDbCommand result = database.Query("SELECT * FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- Dictionary param = new Dictionary();
- param["first"] = user;
- param["second"] = last;
-
- IDbCommand result =
- database.Query("SELECT * FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second", param);
- IDataReader reader = result.ExecuteReader();
-
- UserProfileData row = database.readUserRow(reader);
-
- reader.Close();
- result.Dispose();
-
- return row;
+ return database.readUserRow(reader);
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -191,32 +187,30 @@ namespace OpenSim.Data.MSSQL
try
{
- lock (database)
+ using (IDbCommand adder =
+ database.Query(
+ "INSERT INTO " + m_userFriendsTableName + " " +
+ "(ownerID,friendID,friendPerms,datetimestamp) " +
+ "VALUES " +
+ "(@ownerID,@friendID,@friendPerms,@datetimestamp)",
+ param))
{
- IDbCommand adder =
- database.Query(
- "INSERT INTO " + m_userFriendsTableName + " " +
- "(ownerID,friendID,friendPerms,datetimestamp) " +
- "VALUES " +
- "(@ownerID,@friendID,@friendPerms,@datetimestamp)",
- param);
-
adder.ExecuteNonQuery();
-
- adder =
- database.Query(
- "INSERT INTO " + m_userFriendsTableName + " " +
- "(ownerID,friendID,friendPerms,datetimestamp) " +
- "VALUES " +
- "(@friendID,@ownerID,@friendPerms,@datetimestamp)",
- param);
+ }
+
+ using (IDbCommand adder =
+ database.Query(
+ "INSERT INTO " + m_userFriendsTableName + " " +
+ "(ownerID,friendID,friendPerms,datetimestamp) " +
+ "VALUES " +
+ "(@friendID,@ownerID,@friendPerms,@datetimestamp)",
+ param))
+ {
adder.ExecuteNonQuery();
-
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return;
}
@@ -236,27 +230,26 @@ namespace OpenSim.Data.MSSQL
try
{
- lock (database)
+ using (IDbCommand updater =
+ database.Query(
+ "delete from " + m_userFriendsTableName + " where ownerID = @ownerID and friendID = @friendID",
+ param))
{
- IDbCommand updater =
- database.Query(
- "delete from " + m_userFriendsTableName + " where ownerID = @ownerID and friendID = @friendID",
- param);
updater.ExecuteNonQuery();
-
- updater =
- database.Query(
- "delete from " + m_userFriendsTableName + " where ownerID = @friendID and friendID = @ownerID",
- param);
- updater.ExecuteNonQuery();
-
}
+
+ using (IDbCommand updater =
+ database.Query(
+ "delete from " + m_userFriendsTableName + " where ownerID = @friendID and friendID = @ownerID",
+ param))
+ {
+ updater.ExecuteNonQuery();
+ }
+
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
- return;
}
}
@@ -276,23 +269,19 @@ namespace OpenSim.Data.MSSQL
try
{
- lock (database)
+ using (IDbCommand updater =
+ database.Query(
+ "update " + m_userFriendsTableName +
+ " SET friendPerms = @friendPerms " +
+ "where ownerID = @ownerID and friendID = @friendID",
+ param))
{
- IDbCommand updater =
- database.Query(
- "update " + m_userFriendsTableName +
- " SET friendPerms = @friendPerms " +
- "where ownerID = @ownerID and friendID = @friendID",
- param);
-
updater.ExecuteNonQuery();
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
- return;
}
}
@@ -310,17 +299,14 @@ namespace OpenSim.Data.MSSQL
try
{
- lock (database)
+ //Left Join userfriends to itself
+ using (IDbCommand result =
+ database.Query(
+ "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
+ " where a.ownerID = @ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID",
+ param))
+ using (IDataReader reader = result.ExecuteReader())
{
- //Left Join userfriends to itself
- IDbCommand result =
- database.Query(
- "select a.ownerID,a.friendID,a.friendPerms,b.friendPerms as ownerperms from " + m_userFriendsTableName + " as a, " + m_userFriendsTableName + " as b" +
- " where a.ownerID = @ownerID and b.ownerID = a.friendID and b.friendID = a.ownerID",
- param);
- IDataReader reader = result.ExecuteReader();
-
-
while (reader.Read())
{
FriendListItem fli = new FriendListItem();
@@ -333,15 +319,11 @@ namespace OpenSim.Data.MSSQL
Lfli.Add(fli);
}
- reader.Close();
- result.Dispose();
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
- return Lfli;
}
return Lfli;
@@ -375,19 +357,13 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
+ Dictionary param = new Dictionary();
+ param["first"] = querysplit[0];
+ param["second"] = querysplit[1];
+
+ using (IDbCommand result = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- Dictionary param = new Dictionary();
- param["first"] = querysplit[0];
- param["second"] = querysplit[1];
-
- IDbCommand result =
- database.Query(
- "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first AND lastname = @second",
- param);
- IDataReader reader = result.ExecuteReader();
-
-
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
@@ -395,34 +371,24 @@ namespace OpenSim.Data.MSSQL
user.firstName = (string)reader["username"];
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
- }
- reader.Close();
- result.Dispose();
+ }
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
- return returnlist;
}
}
else if (querysplit.Length == 1)
{
try
{
- lock (database)
+ Dictionary param = new Dictionary();
+ param["first"] = querysplit[0];
+
+ using (IDbCommand result = database.Query("SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first OR lastname = @first", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- Dictionary param = new Dictionary();
- param["first"] = querysplit[0];
-
- IDbCommand result =
- database.Query(
- "SELECT UUID,username,lastname FROM " + m_usersTableName + " WHERE username = @first OR lastname = @first",
- param);
- IDataReader reader = result.ExecuteReader();
-
-
while (reader.Read())
{
AvatarPickerAvatar user = new AvatarPickerAvatar();
@@ -431,15 +397,11 @@ namespace OpenSim.Data.MSSQL
user.lastName = (string)reader["lastname"];
returnlist.Add(user);
}
- reader.Close();
- result.Dispose();
}
- }
+ }
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
- return returnlist;
}
}
return returnlist;
@@ -454,25 +416,17 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
+ Dictionary param = new Dictionary();
+ param["uuid"] = uuid.ToString();
+
+ using (IDbCommand result = database.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = @uuid", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- Dictionary param = new Dictionary();
- param["uuid"] = uuid.ToString();
-
- IDbCommand result = database.Query("SELECT * FROM " + m_usersTableName + " WHERE UUID = @uuid", param);
- IDataReader reader = result.ExecuteReader();
-
- UserProfileData row = database.readUserRow(reader);
-
- reader.Close();
- result.Dispose();
-
- return row;
+ return database.readUserRow(reader);
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -509,25 +463,17 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
+ Dictionary param = new Dictionary();
+ param["uuid"] = uuid.ToString();
+
+ using (IDbCommand result = database.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = @uuid", param))
+ using (IDataReader reader = result.ExecuteReader())
{
- Dictionary param = new Dictionary();
- param["uuid"] = uuid.ToString();
-
- IDbCommand result = database.Query("SELECT * FROM " + m_agentsTableName + " WHERE UUID = @uuid", param);
- IDataReader reader = result.ExecuteReader();
-
- UserAgentData row = database.readAgentRow(reader);
-
- reader.Close();
- result.Dispose();
-
- return row;
+ return database.readAgentRow(reader);
}
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
return null;
}
@@ -554,21 +500,17 @@ namespace OpenSim.Data.MSSQL
{
try
{
- lock (database)
- {
- InsertUserRow(user.ID, user.FirstName, user.SurName, user.PasswordHash, user.PasswordSalt,
- user.HomeRegion, user.HomeLocation.X, user.HomeLocation.Y,
- user.HomeLocation.Z,
- user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created,
- user.LastLogin, user.UserInventoryURI, user.UserAssetURI,
- user.CanDoMask, user.WantDoMask,
- user.AboutText, user.FirstLifeAboutText, user.Image,
- user.FirstLifeImage, user.WebLoginKey);
- }
+ InsertUserRow(user.ID, user.FirstName, user.SurName, user.PasswordHash, user.PasswordSalt,
+ user.HomeRegion, user.HomeLocation.X, user.HomeLocation.Y,
+ user.HomeLocation.Z,
+ user.HomeLookAt.X, user.HomeLookAt.Y, user.HomeLookAt.Z, user.Created,
+ user.LastLogin, user.UserInventoryURI, user.UserAssetURI,
+ user.CanDoMask, user.WantDoMask,
+ user.AboutText, user.FirstLifeAboutText, user.Image,
+ user.FirstLifeImage, user.WebLoginKey);
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
}
}
@@ -646,16 +588,13 @@ namespace OpenSim.Data.MSSQL
parameters["profileFirstImage"] = firstImage.ToString();
parameters["webLoginKey"] = LLUUID.Random().ToString();
- bool returnval = false;
try
{
- IDbCommand result = database.Query(sql, parameters);
-
- if (result.ExecuteNonQuery() == 1)
- returnval = true;
-
- result.Dispose();
+ using (IDbCommand result = database.Query(sql, parameters))
+ {
+ return (result.ExecuteNonQuery() == 1);
+ }
}
catch (Exception e)
{
@@ -663,7 +602,6 @@ namespace OpenSim.Data.MSSQL
return false;
}
- return returnval;
}
///
@@ -682,7 +620,7 @@ namespace OpenSim.Data.MSSQL
///
override public bool UpdateUserProfile(UserProfileData user)
{
- SqlCommand command = new SqlCommand("UPDATE " + m_usersTableName + " set UUID = @uuid, " +
+ using (IDbCommand command = database.Query("UPDATE " + m_usersTableName + " set UUID = @uuid, " +
"username = @username, " +
"lastname = @lastname," +
"passwordHash = @passwordHash," +
@@ -705,71 +643,66 @@ namespace OpenSim.Data.MSSQL
"profileImage = @profileImage," +
"profileFirstImage = @profileFirstImage, " +
"webLoginKey = @webLoginKey where " +
- "UUID = @keyUUUID;", database.getConnection());
- SqlParameter param1 = new SqlParameter("@uuid", user.ID.ToString());
- SqlParameter param2 = new SqlParameter("@username", user.FirstName);
- SqlParameter param3 = new SqlParameter("@lastname", user.SurName);
- SqlParameter param4 = new SqlParameter("@passwordHash", user.PasswordHash);
- SqlParameter param5 = new SqlParameter("@passwordSalt", user.PasswordSalt);
- SqlParameter param6 = new SqlParameter("@homeRegion", Convert.ToInt64(user.HomeRegion));
- SqlParameter param7 = new SqlParameter("@homeLocationX", user.HomeLocation.X);
- SqlParameter param8 = new SqlParameter("@homeLocationY", user.HomeLocation.Y);
- SqlParameter param9 = new SqlParameter("@homeLocationZ", user.HomeLocation.Y);
- SqlParameter param10 = new SqlParameter("@homeLookAtX", user.HomeLookAt.X);
- SqlParameter param11 = new SqlParameter("@homeLookAtY", user.HomeLookAt.Y);
- SqlParameter param12 = new SqlParameter("@homeLookAtZ", user.HomeLookAt.Z);
- SqlParameter param13 = new SqlParameter("@created", Convert.ToInt32(user.Created));
- SqlParameter param14 = new SqlParameter("@lastLogin", Convert.ToInt32(user.LastLogin));
- SqlParameter param15 = new SqlParameter("@userInventoryURI", user.UserInventoryURI);
- SqlParameter param16 = new SqlParameter("@userAssetURI", user.UserAssetURI);
- SqlParameter param17 = new SqlParameter("@profileCanDoMask", Convert.ToInt32(user.CanDoMask));
- SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.WantDoMask));
- SqlParameter param19 = new SqlParameter("@profileAboutText", user.AboutText);
- SqlParameter param20 = new SqlParameter("@profileFirstText", user.FirstLifeAboutText);
- SqlParameter param21 = new SqlParameter("@profileImage", user.Image.ToString());
- SqlParameter param22 = new SqlParameter("@profileFirstImage", user.FirstLifeImage.ToString());
- SqlParameter param23 = new SqlParameter("@keyUUUID", user.ID.ToString());
- SqlParameter param24 = new SqlParameter("@webLoginKey", user.WebLoginKey.UUID.ToString());
- command.Parameters.Add(param1);
- command.Parameters.Add(param2);
- command.Parameters.Add(param3);
- command.Parameters.Add(param4);
- command.Parameters.Add(param5);
- command.Parameters.Add(param6);
- command.Parameters.Add(param7);
- command.Parameters.Add(param8);
- command.Parameters.Add(param9);
- command.Parameters.Add(param10);
- command.Parameters.Add(param11);
- command.Parameters.Add(param12);
- command.Parameters.Add(param13);
- command.Parameters.Add(param14);
- command.Parameters.Add(param15);
- command.Parameters.Add(param16);
- command.Parameters.Add(param17);
- command.Parameters.Add(param18);
- command.Parameters.Add(param19);
- command.Parameters.Add(param20);
- command.Parameters.Add(param21);
- command.Parameters.Add(param22);
- command.Parameters.Add(param23);
- command.Parameters.Add(param24);
- try
+ "UUID = @keyUUUID;"))
{
- int affected = command.ExecuteNonQuery();
- if (affected != 0)
+ SqlParameter param1 = new SqlParameter("@uuid", user.ID.ToString());
+ SqlParameter param2 = new SqlParameter("@username", user.FirstName);
+ SqlParameter param3 = new SqlParameter("@lastname", user.SurName);
+ SqlParameter param4 = new SqlParameter("@passwordHash", user.PasswordHash);
+ SqlParameter param5 = new SqlParameter("@passwordSalt", user.PasswordSalt);
+ SqlParameter param6 = new SqlParameter("@homeRegion", Convert.ToInt64(user.HomeRegion));
+ SqlParameter param7 = new SqlParameter("@homeLocationX", user.HomeLocation.X);
+ SqlParameter param8 = new SqlParameter("@homeLocationY", user.HomeLocation.Y);
+ SqlParameter param9 = new SqlParameter("@homeLocationZ", user.HomeLocation.Y);
+ SqlParameter param10 = new SqlParameter("@homeLookAtX", user.HomeLookAt.X);
+ SqlParameter param11 = new SqlParameter("@homeLookAtY", user.HomeLookAt.Y);
+ SqlParameter param12 = new SqlParameter("@homeLookAtZ", user.HomeLookAt.Z);
+ SqlParameter param13 = new SqlParameter("@created", Convert.ToInt32(user.Created));
+ SqlParameter param14 = new SqlParameter("@lastLogin", Convert.ToInt32(user.LastLogin));
+ SqlParameter param15 = new SqlParameter("@userInventoryURI", user.UserInventoryURI);
+ SqlParameter param16 = new SqlParameter("@userAssetURI", user.UserAssetURI);
+ SqlParameter param17 = new SqlParameter("@profileCanDoMask", Convert.ToInt32(user.CanDoMask));
+ SqlParameter param18 = new SqlParameter("@profileWantDoMask", Convert.ToInt32(user.WantDoMask));
+ SqlParameter param19 = new SqlParameter("@profileAboutText", user.AboutText);
+ SqlParameter param20 = new SqlParameter("@profileFirstText", user.FirstLifeAboutText);
+ SqlParameter param21 = new SqlParameter("@profileImage", user.Image.ToString());
+ SqlParameter param22 = new SqlParameter("@profileFirstImage", user.FirstLifeImage.ToString());
+ SqlParameter param23 = new SqlParameter("@keyUUUID", user.ID.ToString());
+ SqlParameter param24 = new SqlParameter("@webLoginKey", user.WebLoginKey.UUID.ToString());
+ command.Parameters.Add(param1);
+ command.Parameters.Add(param2);
+ command.Parameters.Add(param3);
+ command.Parameters.Add(param4);
+ command.Parameters.Add(param5);
+ command.Parameters.Add(param6);
+ command.Parameters.Add(param7);
+ command.Parameters.Add(param8);
+ command.Parameters.Add(param9);
+ command.Parameters.Add(param10);
+ command.Parameters.Add(param11);
+ command.Parameters.Add(param12);
+ command.Parameters.Add(param13);
+ command.Parameters.Add(param14);
+ command.Parameters.Add(param15);
+ command.Parameters.Add(param16);
+ command.Parameters.Add(param17);
+ command.Parameters.Add(param18);
+ command.Parameters.Add(param19);
+ command.Parameters.Add(param20);
+ command.Parameters.Add(param21);
+ command.Parameters.Add(param22);
+ command.Parameters.Add(param23);
+ command.Parameters.Add(param24);
+ try
{
- return true;
+ int affected = command.ExecuteNonQuery();
+ return (affected != 0);
}
- else
+ catch (Exception e)
{
- return false;
+ m_log.Error(e.ToString());
}
}
- catch (Exception e)
- {
- m_log.Error(e.ToString());
- }
return false;
}
@@ -805,28 +738,21 @@ namespace OpenSim.Data.MSSQL
// return new AvatarAppearance();
try
{
- lock (database)
- {
Dictionary param = new Dictionary();
param["@UUID"] = user.ToString();
- IDbCommand result =
- database.Query("SELECT * FROM avatarappearance WHERE owner = @UUID", param);
- IDataReader reader = result.ExecuteReader();
-
- AvatarAppearance item = null;
- if (reader.Read())
- item = readUserAppearance(reader);
-
- reader.Close();
- result.Dispose();
-
- return item;
- }
+ using (IDbCommand result =
+ database.Query("SELECT * FROM avatarappearance WHERE owner = @UUID", param))
+ using (IDataReader reader = result.ExecuteReader())
+ {
+ AvatarAppearance item = null;
+ if (reader.Read())
+ item = readUserAppearance(reader);
+ return item;
+ }
}
catch (Exception e)
{
- database.Reconnect();
m_log.Error(e.ToString());
}
return null;
@@ -906,49 +832,49 @@ namespace OpenSim.Data.MSSQL
sql += "@jacket_item, @jacket_asset, @gloves_item, @gloves_asset, @undershirt_item, @undershirt_asset, @underpants_item, @underpants_asset, ";
sql += "@skirt_item, @skirt_asset)";
- SqlCommand cmd = new SqlCommand(sql, database.getConnection());
- cmd.Parameters.AddWithValue("@owner", appearance.Owner.ToString());
- cmd.Parameters.AddWithValue("@serial", appearance.Serial);
- cmd.Parameters.AddWithValue("@visual_params", appearance.VisualParams);
- cmd.Parameters.AddWithValue("@texture", appearance.Texture.ToBytes());
- cmd.Parameters.AddWithValue("@avatar_height", appearance.AvatarHeight);
- cmd.Parameters.AddWithValue("@body_item", appearance.BodyItem.ToString());
- cmd.Parameters.AddWithValue("@body_asset", appearance.BodyAsset.ToString());
- cmd.Parameters.AddWithValue("@skin_item", appearance.SkinItem.ToString());
- cmd.Parameters.AddWithValue("@skin_asset", appearance.SkinAsset.ToString());
- cmd.Parameters.AddWithValue("@hair_item", appearance.HairItem.ToString());
- cmd.Parameters.AddWithValue("@hair_asset", appearance.HairAsset.ToString());
- cmd.Parameters.AddWithValue("@eyes_item", appearance.EyesItem.ToString());
- cmd.Parameters.AddWithValue("@eyes_asset", appearance.EyesAsset.ToString());
- cmd.Parameters.AddWithValue("@shirt_item", appearance.ShirtItem.ToString());
- cmd.Parameters.AddWithValue("@shirt_asset", appearance.ShirtAsset.ToString());
- cmd.Parameters.AddWithValue("@pants_item", appearance.PantsItem.ToString());
- cmd.Parameters.AddWithValue("@pants_asset", appearance.PantsAsset.ToString());
- cmd.Parameters.AddWithValue("@shoes_item", appearance.ShoesItem.ToString());
- cmd.Parameters.AddWithValue("@shoes_asset", appearance.ShoesAsset.ToString());
- cmd.Parameters.AddWithValue("@socks_item", appearance.SocksItem.ToString());
- cmd.Parameters.AddWithValue("@socks_asset", appearance.SocksAsset.ToString());
- cmd.Parameters.AddWithValue("@jacket_item", appearance.JacketItem.ToString());
- cmd.Parameters.AddWithValue("@jacket_asset", appearance.JacketAsset.ToString());
- cmd.Parameters.AddWithValue("@gloves_item", appearance.GlovesItem.ToString());
- cmd.Parameters.AddWithValue("@gloves_asset", appearance.GlovesAsset.ToString());
- cmd.Parameters.AddWithValue("@undershirt_item", appearance.UnderShirtItem.ToString());
- cmd.Parameters.AddWithValue("@undershirt_asset", appearance.UnderShirtAsset.ToString());
- cmd.Parameters.AddWithValue("@underpants_item", appearance.UnderPantsItem.ToString());
- cmd.Parameters.AddWithValue("@underpants_asset", appearance.UnderPantsAsset.ToString());
- cmd.Parameters.AddWithValue("@skirt_item", appearance.SkirtItem.ToString());
- cmd.Parameters.AddWithValue("@skirt_asset", appearance.SkirtAsset.ToString());
-
- try
+ using (AutoClosingSqlCommand cmd = database.Query(sql))
{
- cmd.ExecuteNonQuery();
- cmd.Dispose();
+ cmd.Parameters.AddWithValue("@owner", appearance.Owner.ToString());
+ cmd.Parameters.AddWithValue("@serial", appearance.Serial);
+ cmd.Parameters.AddWithValue("@visual_params", appearance.VisualParams);
+ cmd.Parameters.AddWithValue("@texture", appearance.Texture.ToBytes());
+ cmd.Parameters.AddWithValue("@avatar_height", appearance.AvatarHeight);
+ cmd.Parameters.AddWithValue("@body_item", appearance.BodyItem.ToString());
+ cmd.Parameters.AddWithValue("@body_asset", appearance.BodyAsset.ToString());
+ cmd.Parameters.AddWithValue("@skin_item", appearance.SkinItem.ToString());
+ cmd.Parameters.AddWithValue("@skin_asset", appearance.SkinAsset.ToString());
+ cmd.Parameters.AddWithValue("@hair_item", appearance.HairItem.ToString());
+ cmd.Parameters.AddWithValue("@hair_asset", appearance.HairAsset.ToString());
+ cmd.Parameters.AddWithValue("@eyes_item", appearance.EyesItem.ToString());
+ cmd.Parameters.AddWithValue("@eyes_asset", appearance.EyesAsset.ToString());
+ cmd.Parameters.AddWithValue("@shirt_item", appearance.ShirtItem.ToString());
+ cmd.Parameters.AddWithValue("@shirt_asset", appearance.ShirtAsset.ToString());
+ cmd.Parameters.AddWithValue("@pants_item", appearance.PantsItem.ToString());
+ cmd.Parameters.AddWithValue("@pants_asset", appearance.PantsAsset.ToString());
+ cmd.Parameters.AddWithValue("@shoes_item", appearance.ShoesItem.ToString());
+ cmd.Parameters.AddWithValue("@shoes_asset", appearance.ShoesAsset.ToString());
+ cmd.Parameters.AddWithValue("@socks_item", appearance.SocksItem.ToString());
+ cmd.Parameters.AddWithValue("@socks_asset", appearance.SocksAsset.ToString());
+ cmd.Parameters.AddWithValue("@jacket_item", appearance.JacketItem.ToString());
+ cmd.Parameters.AddWithValue("@jacket_asset", appearance.JacketAsset.ToString());
+ cmd.Parameters.AddWithValue("@gloves_item", appearance.GlovesItem.ToString());
+ cmd.Parameters.AddWithValue("@gloves_asset", appearance.GlovesAsset.ToString());
+ cmd.Parameters.AddWithValue("@undershirt_item", appearance.UnderShirtItem.ToString());
+ cmd.Parameters.AddWithValue("@undershirt_asset", appearance.UnderShirtAsset.ToString());
+ cmd.Parameters.AddWithValue("@underpants_item", appearance.UnderPantsItem.ToString());
+ cmd.Parameters.AddWithValue("@underpants_asset", appearance.UnderPantsAsset.ToString());
+ cmd.Parameters.AddWithValue("@skirt_item", appearance.SkirtItem.ToString());
+ cmd.Parameters.AddWithValue("@skirt_asset", appearance.SkirtAsset.ToString());
+
+ try
+ {
+ cmd.ExecuteNonQuery();
+ }
+ catch (Exception e)
+ {
+ m_log.Error(e.ToString());
+ }
}
- catch (Exception e)
- {
- m_log.Error(e.ToString());
- }
- return;
}
///
@@ -958,7 +884,7 @@ namespace OpenSim.Data.MSSQL
/// the item UUID
override public void AddAttachment(LLUUID user, LLUUID item)
{
- return;
+ // TBI?
}
///
@@ -968,7 +894,7 @@ namespace OpenSim.Data.MSSQL
/// the item UUID
override public void RemoveAttachment(LLUUID user, LLUUID item)
{
- return;
+ // TBI?
}
///