I like the adding to the TableAdapter partial class.  What would you think
about an additional constructor too that would take a connection string to
save a constant line of code to set the connection string?

Thanks for the thoughts!

Jeff Block


-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Shawn Wildermuth
Sent: Thursday, January 26, 2006 4:39 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] How to Change the Connection String of a
TypedDataset Data Source

This is one of the inheritent design flaws in the current Typed DataSet
generator.  If you use their Table Adapters you are stuck with the
connection they specify (and to my sheer horror) no way to control the
opening/closing of the connection either. The best way I have seen to
override this behavior is to use the partial class support to create your
own code in the DataSet to fill it yourself with their Table Adapters.  The
way they are built will allow you to do something like this in the partial
class since the connection is internal to the TableAdapter (C# pseudo-code):

partial class MyDataSet
{
  void Fill(string connectionString)
  {
    MySetTableAdapter ta =
      new MySetTableAdapter();
    ta.Connection.ConnectionString = connectionString;
    // ...
  }
}

Or you could allow changing it by adding support to the partial class of the
TableAdapter itself:

MyProject.MySetTableAdapters
{
  public partial class MySetTableAdapter
  {
     public string ConnectionString
    {
      set
      {
        Connection.ConnectionString = value;
      }
      get
      {
        return Connection.ConnectionString;
      }
    }
  }
}


Thanks,

Shawn Wildermuth
http://adoguy.com
C# MVP, Author and Speaker

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Block, Jeffrey A.
(Jeff)
Sent: Thursday, January 26, 2006 4:00 PM
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: [ADVANCED-DOTNET] How to Change the Connection String of a
TypedDataset Data Source

VS 2005, VB.Net

I'm looking for a means of changing the connection string of a typed-dataset
that has been generated by VS 2005 through the data source wizard.  In
reviewing the code, the connection string gets saved as a "setting" for my
application and assigned based on that setting's value.  The setting is
"read-only" since it is an application setting.  Without going against how
VS generates code, is there any way to alter the connection string at
runtime?  The only thing I have come up with so far is change the setting in
the project settings and re-compile, not a real good solution.

Thanks in advance for any thoughts!

Jeffrey A. Block
Sr. Systems Analyst
The Timken Company
[EMAIL PROTECTED]
(330) 471-3268





-----------------------------------------
This message and any attachments are intended for the individual or entity
named above. If you are not the intended recipient, please do not forward,
copy, print, use or disclose this communication to others; also please
notify the sender by replying to this message, and then delete it from your
system. The Timken Company / The Timken Corporation

===================================
This list is hosted by DevelopMentorR  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to