ConnectionUtils.cs 1018 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using cuidian.Common;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. namespace cuidian.Sql
  8. {
  9. public class ConnectionUtils
  10. {
  11. private static ConnectionUtils __instance = new ConnectionUtils();
  12. private Dictionary<string, SqlConnection> __maps = new Dictionary<string, SqlConnection>();
  13. private ConnectionUtils()
  14. { }
  15. public static ConnectionUtils Instance
  16. {
  17. get { return __instance; }
  18. }
  19. public SqlConnection GetConnection()
  20. {
  21. return GetConnection(AppSeting.Instance.GetValue("Traget"));
  22. }
  23. public SqlConnection GetConnection(string key)
  24. {
  25. SqlConnection con;
  26. if (__maps.ContainsKey(key)) return __maps[key];
  27. con = new SqlConnection(AppSeting.Instance.GetConnectstr(key));
  28. //__maps.Add(key, con);
  29. __maps[key] = con;
  30. return con;
  31. }
  32. }
  33. }