12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Configuration;
- using System.Data.SqlClient;
- using System.Web;
- namespace Bowin.Common.Linq.DB
- {
- public class SqlConnectionManager : DbConnectionManager
- {
- public static void InitConnections()
- {
- CloseConnections();
- foreach (ConnectionStringSettings connectionSetting in ((ConnectionStringsSection)(ConfigurationManager.GetSection("connectionStrings"))).ConnectionStrings)
- {
- SqlConnection db = new SqlConnection(connectionSetting.ConnectionString);
- try
- {
- db.Open();
- }
- catch
- {}
- AddConnection(connectionSetting.Name, db);
- }
- IsGlobalConnectionStarted = true;
- }
- public static new SqlConnection GetConnection(string contextKey)
- {
- if (ExistsConnection(contextKey))
- {
- return (SqlConnection)DbConnectionManager.GetConnection(contextKey);
- }
- else
- {
- var connectionSetting = ((ConnectionStringsSection)(ConfigurationManager.GetSection("connectionStrings"))).ConnectionStrings[contextKey];
- SqlConnection db = new SqlConnection(connectionSetting.ConnectionString);
- try
- {
- db.Open();
- }
- catch
- { }
- AddConnection(connectionSetting.Name, db);
- return db;
- }
- }
- }
- }
|