Is MARS no longer necessary!!!

Is MARS no longer necessary!!!

Old forum URL: forums.lhotka.net/forums/t/9380.aspx


Jav posted on Monday, August 16, 2010

While migrating to 4.0 (.net, SL, Csla) and VS10, I was messing around with all parts of my code and config files.  I just noticed that my connectionString no longer has the MultipleActiveResultSets=True. And yet I am not seeing any data access errors.  For example the following code continues works fine.

           using (var ctx = ConnectionManager<SqlConnection>.GetManager("MyConnectionString"))
            {
                using (var cm = ctx.Connection.CreateCommand())
                {
                    cm.CommandType = CommandType.StoredProcedure;
                    cm.CommandText = "Parent_Select";
                    cm.Parameters.AddWithValue("@ParentKey", criteria.Value);
                    using (var dr = new SafeDataReader(cm.ExecuteReader()))
                    {
                        FromDataReader(dr);
                        using (BypassPropertyChecks)
                        {
                            Status = "Retrieved";
                        }
                    }
                    BusinessRules.CheckRules();
                }
                this.childList1 = ChildList1.GetChildList1(this.PrimKey);
                this.childList2 = ChildList2.GetChildList2(this.PrimKey);
                this.childList3 = ChildList3.GetChildList3(this.PrimKey);
            }

So, Is MARS (or using a second connection string) no longer needed? (Or do I have to call Ghostbusters!!)

Jav

tmg4340 replied on Monday, August 16, 2010

I wouldn't call Dan Ackroyd just yet... Smile

MARS enables you to have multiple DataReaders open on the same database connection.  This code only shows one open DataReader, so the MARS attribute doesn't matter here.

HTH

- Scott

Jav replied on Monday, August 16, 2010

Yeah - Now I remember.
Phew! That's a relief.

Jav

Copyright (c) Marimer LLC