none
DataSet Designer: Connection Object RRS feed

  • Question

  • How do I specify my own Connection property source of the DataSet designer?

    I don't mean the ConnectionString - that'd be indirect.

    I don't want to use more than 1 connection object across multiple table objects, and therefore I need to pass the connection object to each DataTable object at the time it is created/initialized.

    Since the Connection property of the DataSet is "internal", I can only guess as to how this might work.

    I will be using a static (private) connection object just like the properties strongly typed class:

    Code Snippet

        internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
           
            private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
           
            public static Settings Default {
                get {
                    return defaultInstance;
                }
            }



    I see the Connection property was intended to be "set" by an external component, But I can't see how since it is "internal".

    Code Snippet

            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            internal System.Data.SqlClient.SqlConnection Connection {
                get {
                    if ((this._connection == null)) {
                        this.InitConnection();
                    }
                    return this._connection;
                }
                set {
                    this._connection = value;
                    if ((this.Adapter.InsertCommand != null)) {
                        this.Adapter.InsertCommand.Connection = value;
                    }
                    if ((this.Adapter.DeleteCommand != null)) {
                        this.Adapter.DeleteCommand.Connection = value;
                    }
                    if ((this.Adapter.UpdateCommand != null)) {
                        this.Adapter.UpdateCommand.Connection = value;
                    }
                    for (int i = 0; (i < this.CommandCollection.Length); i = (i + 1)) {
                        if ((this.CommandCollection[i] != null)) {
                            ((System.Data.SqlClient.SqlCommand)(this.CommandCollection[i])).Connection = value;
                        }
                    }
                }
            }


    What really doesn't make any sense is when I attempt to extend the partial class... I can't even see public properties inside a partial class, a derived class, or even in an instantiated object.  It's like the .Designer.cs keeps everything to itself.  I've even tried changing the "internal" to "public" on the Connection property... nothing seems to expose it.  Yet the strongly typed columns are exposed properly.

    SobyLand.WTF?Connection:NoConnection; // Weird





    Thursday, July 19, 2007 4:01 PM

Answers

  • Figured it out: The "namespace" is the xxxTableAdapters{}

     

    The partial class looks like this:

     

    Code Snippet

    namespace Primary{

        namespace xxxDataSetTableAdapters

        {

            partial class CustomerTableAdapter

            {

                public System.Data.SqlClient.SqlConnection MyConn

                {

                    get

                    {

                        if (!this.Connection.Equals(CustomClass.StaticClassMember.Connection))

                        {

                            this.Connection = CustomClass.StaticClassMember.Connection;

                        }

                        return CustomClass.StaticClassMember.Connection;

                    }

                    set

                    {

                        this.Connection = value;

                    }

                 }

            }

        }

     

        partial class xxxDataSet

        {

        }

    }

     

     

    The only problem: The xxxDataSet still needs to reference the orignal data source, which is a waste of resources

     

     

    Thursday, July 19, 2007 7:18 PM