Duplex client has its own listener loop, so special care on reply is needed.
[mono.git] / mcs / class / System.Data / System.Data.SqlClient / SqlCommand.cs
index 338680db3275d712a20e1f3e3329da8e88cee8e3..b0962359876ee29436e75ccbf9974bb4459915db 100644 (file)
@@ -434,10 +434,14 @@ namespace System.Data.SqlClient {
 
                        string procName = CommandText;
                        string schemaName = String.Empty;
-                       int dotPosition = procName.IndexOf ('.');
+                       int dotPosition = procName.LastIndexOf ('.');
+
+                       // Procedure name can be: [database].[user].[procname]
                        if (dotPosition >= 0) {
                                schemaName = procName.Substring (0, dotPosition);
                                procName = procName.Substring (dotPosition + 1);
+                               if ((dotPosition = schemaName.LastIndexOf ('.')) >= 0)
+                                       schemaName = schemaName.Substring (dotPosition + 1);
                        }
                        
                        procName = EscapeProcName (procName, false);
@@ -588,9 +592,15 @@ namespace System.Data.SqlClient {
                        this.behavior = behavior;
                        if ((behavior & CommandBehavior.SequentialAccess) != 0)
                                Tds.SequentialAccess = true;
-                       Execute (true);
-                       Connection.DataReader = new SqlDataReader (this);
-                       return Connection.DataReader;
+                       try {
+                               Execute (true);
+                               Connection.DataReader = new SqlDataReader (this);
+                               return Connection.DataReader;
+                       } catch {
+                               if ((behavior & CommandBehavior.CloseConnection) != 0)
+                                       Connection.Close ();
+                               throw;
+                       }
                }
 
                public
@@ -696,6 +706,8 @@ namespace System.Data.SqlClient {
                        if (disposed) return;
                        if (disposing) {
                                parameters.Clear();
+                               if (Connection != null)
+                                       Connection.DataReader = null;
                        }
                        base.Dispose (disposing);
                        disposed = true;