aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLAssetData.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/MSSQLAssetData.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/MSSQLAssetData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLAssetData.cs99
1 files changed, 43 insertions, 56 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
index 108ceb1..e0e20df 100644
--- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
@@ -86,19 +86,14 @@ namespace OpenSim.Data.MSSQL
86 /// <returns></returns> 86 /// <returns></returns>
87 override public AssetBase FetchAsset(LLUUID assetID) 87 override public AssetBase FetchAsset(LLUUID assetID)
88 { 88 {
89 AssetBase asset = null;
90
91 Dictionary<string, string> param = new Dictionary<string, string>(); 89 Dictionary<string, string> param = new Dictionary<string, string>();
92 param["id"] = assetID.ToString(); 90 param["id"] = assetID.ToString();
93 91
94 IDbCommand result = database.Query("SELECT * FROM assets WHERE id = @id", param); 92 using (IDbCommand result = database.Query("SELECT * FROM assets WHERE id = @id", param))
95 IDataReader reader = result.ExecuteReader(); 93 using (IDataReader reader = result.ExecuteReader())
96 94 {
97 asset = database.getAssetRow(reader); 95 return database.getAssetRow(reader);
98 reader.Close(); 96 }
99 result.Dispose();
100
101 return asset;
102 } 97 }
103 98
104 /// <summary> 99 /// <summary>
@@ -113,15 +108,13 @@ namespace OpenSim.Data.MSSQL
113 } 108 }
114 109
115 110
116 SqlCommand cmd = 111 using (AutoClosingSqlCommand cmd =
117 new SqlCommand( 112 database.Query(
118 "INSERT INTO assets ([id], [name], [description], [assetType], [local], [temporary], [data])" + 113 "INSERT INTO assets ([id], [name], [description], [assetType], [local], [temporary], [data])" +
119 " VALUES " + 114 " VALUES " +
120 "(@id, @name, @description, @assetType, @local, @temporary, @data)", 115 "(@id, @name, @description, @assetType, @local, @temporary, @data)"))
121 database.getConnection());
122
123 using (cmd)
124 { 116 {
117
125 //SqlParameter p = cmd.Parameters.Add("id", SqlDbType.NVarChar); 118 //SqlParameter p = cmd.Parameters.Add("id", SqlDbType.NVarChar);
126 //p.Value = asset.FullID.ToString(); 119 //p.Value = asset.FullID.ToString();
127 cmd.Parameters.AddWithValue("id", asset.FullID.ToString()); 120 cmd.Parameters.AddWithValue("id", asset.FullID.ToString());
@@ -135,16 +128,8 @@ namespace OpenSim.Data.MSSQL
135 h.Value = asset.Temporary; 128 h.Value = asset.Temporary;
136 SqlParameter i = cmd.Parameters.Add("data", SqlDbType.Image); 129 SqlParameter i = cmd.Parameters.Add("data", SqlDbType.Image);
137 i.Value = asset.Data; 130 i.Value = asset.Data;
138 try
139 {
140 cmd.ExecuteNonQuery();
141 }
142 catch (Exception)
143 {
144 throw;
145 }
146 131
147 cmd.Dispose(); 132 cmd.ExecuteNonQuery();
148 } 133 }
149 } 134 }
150 135
@@ -154,38 +139,40 @@ namespace OpenSim.Data.MSSQL
154 /// <param name="asset">the asset</param> 139 /// <param name="asset">the asset</param>
155 override public void UpdateAsset(AssetBase asset) 140 override public void UpdateAsset(AssetBase asset)
156 { 141 {
157 SqlCommand command = new SqlCommand("UPDATE assets set id = @id, " + 142 using (IDbCommand command = database.Query("UPDATE assets set id = @id, " +
158 "name = @name, " + 143 "name = @name, " +
159 "description = @description," + 144 "description = @description," +
160 "assetType = @assetType," + 145 "assetType = @assetType," +
161 "local = @local," + 146 "local = @local," +
162 "temporary = @temporary," + 147 "temporary = @temporary," +
163 "data = @data where " + 148 "data = @data where " +
164 "id = @keyId;", database.getConnection()); 149 "id = @keyId;"))
165 SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToString());
166 SqlParameter param2 = new SqlParameter("@name", asset.Name);
167 SqlParameter param3 = new SqlParameter("@description", asset.Description);
168 SqlParameter param4 = new SqlParameter("@assetType", asset.Type);
169 SqlParameter param6 = new SqlParameter("@local", asset.Local);
170 SqlParameter param7 = new SqlParameter("@temporary", asset.Temporary);
171 SqlParameter param8 = new SqlParameter("@data", asset.Data);
172 SqlParameter param9 = new SqlParameter("@keyId", asset.FullID.ToString());
173 command.Parameters.Add(param1);
174 command.Parameters.Add(param2);
175 command.Parameters.Add(param3);
176 command.Parameters.Add(param4);
177 command.Parameters.Add(param6);
178 command.Parameters.Add(param7);
179 command.Parameters.Add(param8);
180 command.Parameters.Add(param9);
181
182 try
183 { 150 {
184 command.ExecuteNonQuery(); 151 SqlParameter param1 = new SqlParameter("@id", asset.FullID.ToString());
185 } 152 SqlParameter param2 = new SqlParameter("@name", asset.Name);
186 catch (Exception e) 153 SqlParameter param3 = new SqlParameter("@description", asset.Description);
187 { 154 SqlParameter param4 = new SqlParameter("@assetType", asset.Type);
188 m_log.Error(e.ToString()); 155 SqlParameter param6 = new SqlParameter("@local", asset.Local);
156 SqlParameter param7 = new SqlParameter("@temporary", asset.Temporary);
157 SqlParameter param8 = new SqlParameter("@data", asset.Data);
158 SqlParameter param9 = new SqlParameter("@keyId", asset.FullID.ToString());
159 command.Parameters.Add(param1);
160 command.Parameters.Add(param2);
161 command.Parameters.Add(param3);
162 command.Parameters.Add(param4);
163 command.Parameters.Add(param6);
164 command.Parameters.Add(param7);
165 command.Parameters.Add(param8);
166 command.Parameters.Add(param9);
167
168 try
169 {
170 command.ExecuteNonQuery();
171 }
172 catch (Exception e)
173 {
174 m_log.Error(e.ToString());
175 }
189 } 176 }
190 } 177 }
191 178
@@ -228,12 +215,12 @@ namespace OpenSim.Data.MSSQL
228 /// <remarks>it use mssql_connection.ini</remarks> 215 /// <remarks>it use mssql_connection.ini</remarks>
229 override public void Initialise() 216 override public void Initialise()
230 { 217 {
231 IniFile GridDataMySqlFile = new IniFile("mssql_connection.ini"); 218 IniFile gridDataMSSqlFile = new IniFile("mssql_connection.ini");
232 string settingDataSource = GridDataMySqlFile.ParseFileReadValue("data_source"); 219 string settingDataSource = gridDataMSSqlFile.ParseFileReadValue("data_source");
233 string settingInitialCatalog = GridDataMySqlFile.ParseFileReadValue("initial_catalog"); 220 string settingInitialCatalog = gridDataMSSqlFile.ParseFileReadValue("initial_catalog");
234 string settingPersistSecurityInfo = GridDataMySqlFile.ParseFileReadValue("persist_security_info"); 221 string settingPersistSecurityInfo = gridDataMSSqlFile.ParseFileReadValue("persist_security_info");
235 string settingUserId = GridDataMySqlFile.ParseFileReadValue("user_id"); 222 string settingUserId = gridDataMSSqlFile.ParseFileReadValue("user_id");
236 string settingPassword = GridDataMySqlFile.ParseFileReadValue("password"); 223 string settingPassword = gridDataMSSqlFile.ParseFileReadValue("password");
237 224
238 database = 225 database =
239 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId, 226 new MSSQLManager(settingDataSource, settingInitialCatalog, settingPersistSecurityInfo, settingUserId,