SqliteRoleProvider.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. //
  2. // $Id: PgRoleProvider.cs 12 2007-10-17 17:22:43Z dna $
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining
  5. // a copy of this software and associated documentation files (the
  6. // "Software"), to deal in the Software without restriction, including
  7. // without limitation the rights to use, copy, modify, merge, publish,
  8. // distribute, sublicense, and/or sell copies of the Software, and to
  9. // permit persons to whom the Software is furnished to do so, subject to
  10. // the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be
  13. // included in all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  16. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  17. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  18. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  19. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  20. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  21. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. //
  23. // Copyright © 2006, 2007 Nauck IT KG http://www.nauck-it.de
  24. //
  25. // Author:
  26. // Daniel Nauck <d.nauck(at)nauck-it.de>
  27. //
  28. // Adapted to Sqlite by Marek Habersack <[email protected]>
  29. //
  30. #if NET_2_0
  31. using System;
  32. using System.Data;
  33. using System.Data.Common;
  34. using System.Collections.Generic;
  35. using System.Collections.Specialized;
  36. using System.Diagnostics;
  37. using System.Text;
  38. using System.Configuration;
  39. using System.Configuration.Provider;
  40. using System.Web.Hosting;
  41. using System.Web.Security;
  42. using Mono.Data.Sqlite;
  43. namespace System.Web.Security
  44. {
  45. internal class SqliteRoleProvider : RoleProvider
  46. {
  47. private const string m_RolesTableName = "Roles";
  48. private const string m_UserInRolesTableName = "UsersInRoles";
  49. private string m_ConnectionString = string.Empty;
  50. DbParameter AddParameter (DbCommand command, string parameterName)
  51. {
  52. return AddParameter (command, parameterName, null);
  53. }
  54. DbParameter AddParameter (DbCommand command, string parameterName, object parameterValue)
  55. {
  56. return AddParameter (command, parameterName, ParameterDirection.Input, parameterValue);
  57. }
  58. DbParameter AddParameter (DbCommand command, string parameterName, ParameterDirection direction, object parameterValue)
  59. {
  60. DbParameter dbp = command.CreateParameter ();
  61. dbp.ParameterName = parameterName;
  62. dbp.Value = parameterValue;
  63. dbp.Direction = direction;
  64. command.Parameters.Add (dbp);
  65. return dbp;
  66. }
  67. DbParameter AddParameter (DbCommand command, string parameterName, ParameterDirection direction, DbType type, object parameterValue)
  68. {
  69. DbParameter dbp = command.CreateParameter ();
  70. dbp.ParameterName = parameterName;
  71. dbp.Value = parameterValue;
  72. dbp.Direction = direction;
  73. dbp.DbType = type;
  74. command.Parameters.Add (dbp);
  75. return dbp;
  76. }
  77. /// <summary>
  78. /// System.Configuration.Provider.ProviderBase.Initialize Method
  79. /// </summary>
  80. public override void Initialize(string name, NameValueCollection config)
  81. {
  82. // Initialize values from web.config.
  83. if (config == null)
  84. throw new ArgumentNullException("Config", Properties.Resources.ErrArgumentNull);
  85. if (string.IsNullOrEmpty(name))
  86. name = Properties.Resources.RoleProviderDefaultName;
  87. if (string.IsNullOrEmpty(config["description"]))
  88. {
  89. config.Remove("description");
  90. config.Add("description", Properties.Resources.RoleProviderDefaultDescription);
  91. }
  92. // Initialize the abstract base class.
  93. base.Initialize(name, config);
  94. m_ApplicationName = GetConfigValue(config["applicationName"], HostingEnvironment.ApplicationVirtualPath);
  95. // Get connection string.
  96. string connStrName = config["connectionStringName"];
  97. if (string.IsNullOrEmpty(connStrName))
  98. {
  99. throw new ArgumentOutOfRangeException("ConnectionStringName", Properties.Resources.ErrArgumentNullOrEmpty);
  100. }
  101. else
  102. {
  103. ConnectionStringSettings ConnectionStringSettings = ConfigurationManager.ConnectionStrings[connStrName];
  104. if (ConnectionStringSettings == null || string.IsNullOrEmpty(ConnectionStringSettings.ConnectionString.Trim()))
  105. {
  106. throw new ProviderException(Properties.Resources.ErrConnectionStringNullOrEmpty);
  107. }
  108. m_ConnectionString = ConnectionStringSettings.ConnectionString;
  109. }
  110. }
  111. /// <summary>
  112. /// System.Web.Security.RoleProvider properties.
  113. /// </summary>
  114. #region System.Web.Security.RoleProvider properties
  115. private string m_ApplicationName = string.Empty;
  116. public override string ApplicationName
  117. {
  118. get { return m_ApplicationName; }
  119. set { m_ApplicationName = value; }
  120. }
  121. #endregion
  122. /// <summary>
  123. /// System.Web.Security.RoleProvider methods.
  124. /// </summary>
  125. #region System.Web.Security.RoleProvider methods
  126. /// <summary>
  127. /// RoleProvider.AddUsersToRoles
  128. /// </summary>
  129. public override void AddUsersToRoles(string[] userNames, string[] roleNames)
  130. {
  131. foreach (string rolename in roleNames)
  132. {
  133. if (!RoleExists(rolename))
  134. {
  135. throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, rolename));
  136. }
  137. }
  138. foreach (string username in userNames)
  139. {
  140. foreach (string rolename in roleNames)
  141. {
  142. if (IsUserInRole(username, rolename))
  143. {
  144. throw new ProviderException(string.Format(Properties.Resources.ErrUserAlreadyInRole, username, rolename));
  145. }
  146. }
  147. }
  148. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  149. {
  150. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  151. {
  152. dbCommand.CommandText = string.Format("INSERT INTO \"{0}\" (\"Username\", \"Rolename\", \"ApplicationName\") Values (@Username, @Rolename, @ApplicationName)", m_UserInRolesTableName);
  153. AddParameter (dbCommand, "@Username");
  154. AddParameter (dbCommand, "@Rolename");
  155. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  156. SqliteTransaction dbTrans = null;
  157. try
  158. {
  159. dbConn.Open();
  160. dbCommand.Prepare();
  161. using (dbTrans = dbConn.BeginTransaction())
  162. {
  163. foreach (string username in userNames)
  164. {
  165. foreach (string rolename in roleNames)
  166. {
  167. dbCommand.Parameters["@Username"].Value = username;
  168. dbCommand.Parameters["@Rolename"].Value = rolename;
  169. dbCommand.ExecuteNonQuery();
  170. }
  171. }
  172. // Attempt to commit the transaction
  173. dbTrans.Commit();
  174. }
  175. }
  176. catch (SqliteException e)
  177. {
  178. Trace.WriteLine(e.ToString());
  179. try
  180. {
  181. // Attempt to roll back the transaction
  182. Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
  183. dbTrans.Rollback();
  184. }
  185. catch (SqliteException re)
  186. {
  187. // Rollback failed
  188. Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
  189. Trace.WriteLine(re.ToString());
  190. }
  191. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  192. }
  193. finally
  194. {
  195. if (dbConn != null)
  196. dbConn.Close();
  197. }
  198. }
  199. }
  200. }
  201. /// <summary>
  202. /// RoleProvider.CreateRole
  203. /// </summary>
  204. public override void CreateRole(string roleName)
  205. {
  206. if (RoleExists(roleName))
  207. {
  208. throw new ProviderException(string.Format(Properties.Resources.ErrRoleAlreadyExist, roleName));
  209. }
  210. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  211. {
  212. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  213. {
  214. dbCommand.CommandText = string.Format("INSERT INTO \"{0}\" (\"Rolename\", \"ApplicationName\") Values (@Rolename, @ApplicationName)", m_RolesTableName);
  215. AddParameter (dbCommand, "@Rolename", roleName);
  216. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  217. try
  218. {
  219. dbConn.Open();
  220. dbCommand.Prepare();
  221. dbCommand.ExecuteNonQuery();
  222. }
  223. catch (SqliteException e)
  224. {
  225. Trace.WriteLine(e.ToString());
  226. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  227. }
  228. finally
  229. {
  230. if (dbConn != null)
  231. dbConn.Close();
  232. }
  233. }
  234. }
  235. }
  236. /// <summary>
  237. /// RoleProvider.DeleteRole
  238. /// </summary>
  239. public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
  240. {
  241. if (!RoleExists(roleName))
  242. {
  243. throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, roleName));
  244. }
  245. if (throwOnPopulatedRole && GetUsersInRole(roleName).Length > 0)
  246. {
  247. throw new ProviderException(Properties.Resources.ErrCantDeletePopulatedRole);
  248. }
  249. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  250. {
  251. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  252. {
  253. dbCommand.CommandText = string.Format("DELETE FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_RolesTableName);
  254. AddParameter (dbCommand, "@Rolename", roleName);
  255. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  256. SqliteTransaction dbTrans = null;
  257. try
  258. {
  259. dbConn.Open();
  260. dbCommand.Prepare();
  261. using (dbTrans = dbConn.BeginTransaction())
  262. {
  263. dbCommand.ExecuteNonQuery();
  264. // Attempt to commit the transaction
  265. dbTrans.Commit();
  266. }
  267. }
  268. catch (SqliteException e)
  269. {
  270. Trace.WriteLine(e.ToString());
  271. try
  272. {
  273. // Attempt to roll back the transaction
  274. Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
  275. dbTrans.Rollback();
  276. }
  277. catch (SqliteException re)
  278. {
  279. // Rollback failed
  280. Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
  281. Trace.WriteLine(re.ToString());
  282. }
  283. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  284. }
  285. finally
  286. {
  287. if (dbConn != null)
  288. dbConn.Close();
  289. }
  290. }
  291. }
  292. return true;
  293. }
  294. /// <summary>
  295. /// RoleProvider.FindUsersInRole
  296. /// </summary>
  297. public override string[] FindUsersInRole(string roleName, string usernameToMatch)
  298. {
  299. List<string> userList = new List<string>();
  300. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  301. {
  302. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  303. {
  304. dbCommand.CommandText = string.Format("SELECT \"Username\" FROM \"{0}\" WHERE \"Username\" LIKE @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName ORDER BY \"Username\" ASC", m_UserInRolesTableName);
  305. AddParameter (dbCommand, "@Username", usernameToMatch);
  306. AddParameter (dbCommand, "@Rolename", roleName);
  307. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  308. try
  309. {
  310. dbConn.Open();
  311. dbCommand.Prepare();
  312. using (SqliteDataReader reader = dbCommand.ExecuteReader())
  313. {
  314. if (reader.HasRows)
  315. {
  316. while (reader.Read())
  317. {
  318. userList.Add(reader.GetString(0));
  319. }
  320. }
  321. }
  322. }
  323. catch (SqliteException e)
  324. {
  325. Trace.WriteLine(e.ToString());
  326. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  327. }
  328. finally
  329. {
  330. if (dbConn != null)
  331. dbConn.Close();
  332. }
  333. }
  334. }
  335. return userList.ToArray();
  336. }
  337. /// <summary>
  338. /// RoleProvider.GetAllRoles
  339. /// </summary>
  340. public override string[] GetAllRoles()
  341. {
  342. List<string> rolesList = new List<string>();
  343. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  344. {
  345. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  346. {
  347. dbCommand.CommandText = string.Format("SELECT \"Rolename\" FROM \"{0}\" WHERE \"ApplicationName\" = @ApplicationName ORDER BY \"Rolename\" ASC", m_RolesTableName);
  348. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  349. try
  350. {
  351. dbConn.Open();
  352. dbCommand.Prepare();
  353. using (SqliteDataReader reader = dbCommand.ExecuteReader())
  354. {
  355. while (reader.Read())
  356. {
  357. rolesList.Add(reader.GetString(0));
  358. }
  359. }
  360. }
  361. catch (SqliteException e)
  362. {
  363. Trace.WriteLine(e.ToString());
  364. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  365. }
  366. finally
  367. {
  368. if (dbConn != null)
  369. dbConn.Close();
  370. }
  371. }
  372. }
  373. return rolesList.ToArray();
  374. }
  375. /// <summary>
  376. /// RoleProvider.GetRolesForUser
  377. /// </summary>
  378. public override string[] GetRolesForUser(string username)
  379. {
  380. List<string> rolesList = new List<string>();
  381. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  382. {
  383. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  384. {
  385. dbCommand.CommandText = string.Format("SELECT \"Rolename\" FROM \"{0}\" WHERE \"Username\" = @Username AND \"ApplicationName\" = @ApplicationName ORDER BY \"Rolename\" ASC", m_UserInRolesTableName);
  386. AddParameter (dbCommand, "@Username", username);
  387. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  388. try
  389. {
  390. dbConn.Open();
  391. dbCommand.Prepare();
  392. using (SqliteDataReader reader = dbCommand.ExecuteReader())
  393. {
  394. if (reader.HasRows)
  395. {
  396. while (reader.Read())
  397. {
  398. rolesList.Add(reader.GetString(0));
  399. }
  400. }
  401. }
  402. }
  403. catch (SqliteException e)
  404. {
  405. Trace.WriteLine(e.ToString());
  406. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  407. }
  408. finally
  409. {
  410. if (dbConn != null)
  411. dbConn.Close();
  412. }
  413. }
  414. }
  415. return rolesList.ToArray();
  416. }
  417. /// <summary>
  418. /// RoleProvider.GetUsersInRole
  419. /// </summary>
  420. public override string[] GetUsersInRole(string roleName)
  421. {
  422. List<string> userList = new List<string>();
  423. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  424. {
  425. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  426. {
  427. dbCommand.CommandText = string.Format("SELECT \"Username\" FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName ORDER BY \"Username\" ASC", m_UserInRolesTableName);
  428. AddParameter (dbCommand, "@Rolename", roleName);
  429. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  430. try
  431. {
  432. dbConn.Open();
  433. dbCommand.Prepare();
  434. using (SqliteDataReader reader = dbCommand.ExecuteReader())
  435. {
  436. if (reader.HasRows)
  437. {
  438. while (reader.Read())
  439. {
  440. userList.Add(reader.GetString(0));
  441. }
  442. }
  443. }
  444. }
  445. catch (SqliteException e)
  446. {
  447. Trace.WriteLine(e.ToString());
  448. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  449. }
  450. finally
  451. {
  452. if (dbConn != null)
  453. dbConn.Close();
  454. }
  455. }
  456. }
  457. return userList.ToArray();
  458. }
  459. /// <summary>
  460. /// RoleProvider.IsUserInRole
  461. /// </summary>
  462. public override bool IsUserInRole(string userName, string roleName)
  463. {
  464. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  465. {
  466. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  467. {
  468. dbCommand.CommandText = string.Format("SELECT COUNT(*) FROM \"{0}\" WHERE \"Username\" = @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_UserInRolesTableName);
  469. AddParameter (dbCommand, "@Username", userName);
  470. AddParameter (dbCommand, "@Rolename", roleName);
  471. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  472. try
  473. {
  474. dbConn.Open();
  475. dbCommand.Prepare();
  476. int numRecs = 0;
  477. Int32.TryParse(dbCommand.ExecuteScalar().ToString(), out numRecs);
  478. if (numRecs > 0)
  479. return true;
  480. }
  481. catch (SqliteException e)
  482. {
  483. Trace.WriteLine(e.ToString());
  484. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  485. }
  486. finally
  487. {
  488. if (dbConn != null)
  489. dbConn.Close();
  490. }
  491. }
  492. }
  493. return false;
  494. }
  495. /// <summary>
  496. /// RoleProvider.RemoveUsersFromRoles
  497. /// </summary>
  498. public override void RemoveUsersFromRoles(string[] userNames, string[] roleNames)
  499. {
  500. foreach (string rolename in roleNames)
  501. {
  502. if (!RoleExists(rolename))
  503. {
  504. throw new ProviderException(string.Format(Properties.Resources.ErrRoleNotExist, rolename));
  505. }
  506. }
  507. foreach (string username in userNames)
  508. {
  509. foreach (string rolename in roleNames)
  510. {
  511. if (!IsUserInRole(username, rolename))
  512. {
  513. throw new ProviderException(string.Format(Properties.Resources.ErrUserIsNotInRole, username, rolename));
  514. }
  515. }
  516. }
  517. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  518. {
  519. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  520. {
  521. dbCommand.CommandText = string.Format("DELETE FROM \"{0}\" WHERE \"Username\" = @Username AND \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_UserInRolesTableName);
  522. AddParameter (dbCommand, "@Username");
  523. AddParameter (dbCommand, "@Rolename");
  524. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  525. SqliteTransaction dbTrans = null;
  526. try
  527. {
  528. dbConn.Open();
  529. dbCommand.Prepare();
  530. using (dbTrans = dbConn.BeginTransaction())
  531. {
  532. foreach (string username in userNames)
  533. {
  534. foreach (string rolename in roleNames)
  535. {
  536. dbCommand.Parameters["@Username"].Value = username;
  537. dbCommand.Parameters["@Rolename"].Value = rolename;
  538. dbCommand.ExecuteNonQuery();
  539. }
  540. }
  541. // Attempt to commit the transaction
  542. dbTrans.Commit();
  543. }
  544. }
  545. catch (SqliteException e)
  546. {
  547. Trace.WriteLine(e.ToString());
  548. try
  549. {
  550. // Attempt to roll back the transaction
  551. Trace.WriteLine(Properties.Resources.LogRollbackAttempt);
  552. dbTrans.Rollback();
  553. }
  554. catch (SqliteException re)
  555. {
  556. // Rollback failed
  557. Trace.WriteLine(Properties.Resources.ErrRollbackFailed);
  558. Trace.WriteLine(re.ToString());
  559. }
  560. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  561. }
  562. finally
  563. {
  564. if (dbConn != null)
  565. dbConn.Close();
  566. }
  567. }
  568. }
  569. }
  570. /// <summary>
  571. /// RoleProvider.RoleExists
  572. /// </summary>
  573. public override bool RoleExists(string roleName)
  574. {
  575. using (SqliteConnection dbConn = new SqliteConnection(m_ConnectionString))
  576. {
  577. using (SqliteCommand dbCommand = dbConn.CreateCommand())
  578. {
  579. dbCommand.CommandText = string.Format("SELECT COUNT(*) FROM \"{0}\" WHERE \"Rolename\" = @Rolename AND \"ApplicationName\" = @ApplicationName", m_RolesTableName);
  580. AddParameter (dbCommand, "@Rolename", roleName);
  581. AddParameter (dbCommand, "@ApplicationName", m_ApplicationName);
  582. try
  583. {
  584. dbConn.Open();
  585. dbCommand.Prepare();
  586. int numRecs = 0;
  587. Int32.TryParse(dbCommand.ExecuteScalar().ToString(), out numRecs);
  588. if (numRecs > 0)
  589. return true;
  590. }
  591. catch (SqliteException e)
  592. {
  593. Trace.WriteLine(e.ToString());
  594. throw new ProviderException(Properties.Resources.ErrOperationAborted);
  595. }
  596. finally
  597. {
  598. if (dbConn != null)
  599. dbConn.Close();
  600. }
  601. }
  602. }
  603. return false;
  604. }
  605. #endregion
  606. #region private methods
  607. /// <summary>
  608. /// A helper function to retrieve config values from the configuration file.
  609. /// </summary>
  610. /// <param name="configValue"></param>
  611. /// <param name="defaultValue"></param>
  612. /// <returns></returns>
  613. private string GetConfigValue(string configValue, string defaultValue)
  614. {
  615. if (string.IsNullOrEmpty(configValue))
  616. return defaultValue;
  617. return configValue;
  618. }
  619. #endregion
  620. }
  621. }
  622. #endif