Răsfoiți Sursa

2009-04-03 Marek Habersack <[email protected]>

	* SessionSQLServerHandler.cs: recreate connection after database
	became unavailable but the session handler is still alive. Fixes
	bug #491508. Patch from Hubert Fongarnand
	<[email protected]>, thanks!

svn path=/trunk/mcs/; revision=130972
Marek Habersack 17 ani în urmă
părinte
comite
ca5554b9ec

+ 7 - 0
mcs/class/System.Web/System.Web.SessionState/ChangeLog

@@ -1,3 +1,10 @@
+2009-04-03  Marek Habersack  <[email protected]>
+
+	* SessionSQLServerHandler.cs: recreate connection after database
+	became unavailable but the session handler is still alive. Fixes
+	bug #491508. Patch from Hubert Fongarnand
+	<[email protected]>, thanks!
+
 2008-10-21  Marek Habersack  <[email protected]>
 
 	* SessionStateModule.cs: OnAcquireState should set up a session

+ 22 - 15
mcs/class/System.Web/System.Web.SessionState/SessionSQLServerHandler.cs

@@ -67,25 +67,11 @@ namespace System.Web.SessionState {
 		public void Init (SessionStateModule module, HttpApplication context,
 				  SessionConfig config)
 		{
-			string connectionTypeName;
-			string providerAssemblyName;
-			string cncString;
+
 
 			this.config = config;
 			this.AppPath = context.Request.ApplicationPath;
 			
-			GetConnectionData (out providerAssemblyName, out connectionTypeName, out cncString);
-			if (cncType == null) {
-				Assembly dbAssembly = Assembly.Load (providerAssemblyName);
-				cncType = dbAssembly.GetType (connectionTypeName, true);
-				if (!typeof (IDbConnection).IsAssignableFrom (cncType))
-					throw new ApplicationException ("The type '" + cncType +
-							"' does not implement IDB Connection.\n" +
-							"Check 'DbConnectionType' in server.exe.config.");
-			}
-
-			cnc = (IDbConnection) Activator.CreateInstance (cncType);
-			cnc.ConnectionString = cncString;
 			try {
 				InitializeConnection ();
 			} catch (Exception exc) {
@@ -100,6 +86,25 @@ namespace System.Web.SessionState {
 				ReplaceParamPrefix (ref deleteCommandText);
 			}
 		}
+		
+		void CreateNewConnection() 
+		{
+			string connectionTypeName;
+			string providerAssemblyName;
+			string cncString;
+			GetConnectionData (out providerAssemblyName, out connectionTypeName, out cncString);
+			if (cncType == null) {
+				Assembly dbAssembly = Assembly.Load (providerAssemblyName);
+				cncType = dbAssembly.GetType (connectionTypeName, true);
+				if (!typeof (IDbConnection).IsAssignableFrom (cncType))
+					throw new ApplicationException ("The type '" + cncType +
+							"' does not implement IDB Connection.\n" +
+							"Check 'DbConnectionType' in server.exe.config.");
+			}
+
+			cnc = (IDbConnection) Activator.CreateInstance (cncType);
+			cnc.ConnectionString = cncString;
+		}
 
 		void ReplaceParamPrefix(ref string command)
 		{
@@ -317,6 +322,8 @@ namespace System.Web.SessionState {
 
 		void InitializeConnection()
 		{
+			if (cnc == null)
+				CreateNewConnection();
 			cnc.Open ();
 			selectCommand = cnc.CreateCommand ();
 			selectCommand.CommandText = selectCommandText;