* SqlConnection.cs: Use null as default value for connectionString
authorGert Driesen <drieseng@users.sourceforge.net>
Mon, 28 Jul 2008 14:46:55 +0000 (14:46 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Mon, 28 Jul 2008 14:46:55 +0000 (14:46 -0000)
field. Remove Init method, as initialization is done in
SetDefaultConnectionParameters. Initialize parms in
SetDefaultConnectionParameters to avoid calling Reset on newly
initialized collection. In Dispose (bool), also invoke base.Dispose if
SqlConnection was already disposed. Fixes bug #412571.
* SqlConnectionTest.cs: Enabled and improved test for bug #412571.

svn path=/trunk/mcs/; revision=109013

mcs/class/System.Data/System.Data.SqlClient/ChangeLog
mcs/class/System.Data/System.Data.SqlClient/SqlConnection.cs
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/ChangeLog
mcs/class/System.Data/Test/ProviderTests/System.Data.SqlClient/SqlConnectionTest.cs

index c1abd585812f5d59de5921da633059de8947ff6b..87956b8d0c1e6a816141a6cd52d351349fae2853 100644 (file)
@@ -1,6 +1,15 @@
 2008-07-28  Gert Driesen  <drieseng@users.sourceforge.net>
 
-       * SqlConnection.cs(ChangeState): Return immediately when new state
+       * SqlConnection.cs: Use null as default value for connectionString
+       field. Remove Init method, as initialization is done in
+       SetDefaultConnectionParameters. Initialize parms in
+       SetDefaultConnectionParameters to avoid calling Reset on newly
+       initialized collection. In Dispose (bool), also invoke base.Dispose if
+       SqlConnection was already disposed. Fixes bug #412571. 
+
+2008-07-28  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * SqlConnection.cs (ChangeState): Return immediately when new state
        equals original state. Fixes bug #412574. Removed extra whitespace.
 
 2008-07-23  Veerapuram Varadhan  <vvaradhan@novell.com>
index b2ef5710ce3de98ec3b3c172028eba5c429d6c4a..273256f9d25b1f1bf85e88c2fbdc5e3bcf32550a 100644 (file)
@@ -91,7 +91,7 @@ namespace System.Data.SqlClient
 
                // Connection parameters
                
-               TdsConnectionParameters parms = new TdsConnectionParameters ();
+               TdsConnectionParameters parms;
                bool connectionReset;
                bool pooling;
                string dataSource;
@@ -117,21 +117,12 @@ namespace System.Data.SqlClient
 
                #region Constructors
 
-               public SqlConnection () : this (String.Empty)
+               public SqlConnection () : this (null)
                {
                }
        
                public SqlConnection (string connectionString)
                {
-                       Init (connectionString);
-               }
-
-               private void Init (string connectionString)
-               {
-                       connectionTimeout = DEFAULT_CONNECTIONTIMEOUT;
-                       dataSource = string.Empty;
-                       packetSize = DEFAULT_PACKETSIZE;
-                       port = DEFAULT_PORT;
                        ConnectionString = connectionString;
                }
 
@@ -160,7 +151,7 @@ namespace System.Data.SqlClient
                        set {
                                if (state == ConnectionState.Open)
                                        throw new InvalidOperationException ("Not Allowed to change ConnectionString property while Connection state is OPEN");
-                               SetConnectionString (value); 
+                               SetConnectionString (value);
                        }
                }
        
@@ -465,14 +456,11 @@ namespace System.Data.SqlClient
 
                protected override void Dispose (bool disposing)
                {
-                       if (disposed)
-                               return;
-
                        try {
-                               if (disposing) {
+                               if (disposing && !disposed) {
                                        if (State == ConnectionState.Open) 
                                                Close ();
-                                       ConnectionString = string.Empty;
+                                       ConnectionString = null;
                                }
                        } finally {
                                disposed = true;
@@ -740,7 +728,10 @@ namespace System.Data.SqlClient
 
                void SetDefaultConnectionParameters ()
                {
-                       parms.Reset ();
+                       if (parms == null)
+                               parms = new TdsConnectionParameters ();
+                       else
+                               parms.Reset ();
                        dataSource = string.Empty;
                        connectionTimeout = DEFAULT_CONNECTIONTIMEOUT;
                        connectionReset = true;
@@ -748,6 +739,7 @@ namespace System.Data.SqlClient
                        maxPoolSize = DEFAULT_MAXPOOLSIZE;
                        minPoolSize = DEFAULT_MINPOOLSIZE;
                        packetSize = DEFAULT_PACKETSIZE;
+                       port = DEFAULT_PORT;
  #if NET_2_0
                        async = false;
  #endif
index fae87d28da3cd2042ffdd276eb1db774d59b6f9c..e5f7b53e21dbf1b05276b0ec020342dbfeaa3c95 100644 (file)
@@ -1,3 +1,7 @@
+2008-07-28  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * SqlConnectionTest.cs: Enabled and improved test for bug #412571.
+
 2008-07-28  Gert Driesen  <drieseng@users.sourceforge.net>
 
        * SqlConnectionTest.cs: Enabled test for bug #412574.
index 19c9f915696b00dc88b84637923562c1d01e1ed4..79b9bee1f317e24fb0f7f4a57d804dd438e7c157 100644 (file)
@@ -494,19 +494,27 @@ namespace MonoTests.System.Data
                [Test] // bug #412571
                public void Dispose ()
                {
-                       Assert.Ignore ("bug #412571");
-
                        StateChangeEventArgs stateChangeArgs;
                        EventArgs disposedArgs;
 
-                       conn = new SqlConnection (connectionString);
+                       conn = new SqlConnection (connectionString + ";Connection Timeout=30;Packet Size=512;Workstation Id=Desktop");
                        conn.Disposed += new EventHandler (Connection_Disposed);
                        conn.Open ();
                        conn.StateChange += new StateChangeEventHandler (Connection_StateChange);
                        Assert.AreEqual (0, events.Count, "#A1");
                        conn.Dispose ();
-                       Assert.AreEqual (ConnectionState.Closed, conn.State, "#A2");
-                       Assert.AreEqual (2, events.Count, "#A3");
+                       Assert.AreEqual (string.Empty, conn.ConnectionString, "#A2");
+                       Assert.AreEqual (15, conn.ConnectionTimeout, "#A3");
+                       Assert.AreEqual (string.Empty, conn.Database, "#A4");
+                       Assert.AreEqual (string.Empty, conn.DataSource, "#A5");
+#if NET_2_0
+                       Assert.AreEqual (8000, conn.PacketSize, "#A6");
+#else
+                       Assert.AreEqual (8192, conn.PacketSize, "#A6");
+#endif
+                       Assert.AreEqual (ConnectionState.Closed, conn.State, "#A7");
+                       Assert.IsTrue (string.Compare (conn.WorkstationId, Environment.MachineName, true) == 0, "#A8");
+                       Assert.AreEqual (2, events.Count, "#A9");
 
                        stateChangeArgs = events [0] as StateChangeEventArgs;
                        Assert.IsNotNull (stateChangeArgs, "#B1");