.Net: ...TableAdapter does not contain a definition for 'Connection'

by matt 17. March 2009 21:14

When you are first playing with table adapters you might get to see.  When you create your typed data set, Visual Studio will create an element in the generated XSD that contains the connection string that you were using.  This will more than likely not be the connection string that you want to use in your production environment.  So how do you go about changing it?  Well, if you start using the intellisense in Visual Studio, you will soon find that there is a 'Connection' property on the table adapter once you have created it. 

Great!  Lets set the connection string on that and well be done.  Ah, not so easy.  This will compile just fine, but as Connection is in fact an internal member, it is only available within the same assembly.  So if you are trying to access your data set from another assembly (which is often the case) you won't be able to set it.

I've seen a number of people asking for a way to resolve this, and luckily the solution is simple and can be resolved by taking the following steps:

  1. In the design view of the dataset, select the table adapter that you want to change the connection for.
    TableAdapter
  2. Open the properties of the Adapter (<F4> in Visual Studio) and change the Connection Modifier property to public.
    Properties

That should do it, you should then be able to use something like the following to change your connection:

string myNewConnectionString = "Data Source=(local);Initial Catalog=MyStore;Integrated Security=True";
TestDataSetTableAdapters.OrderTableAdapter ta = new DataSetTests.TestDataSetTableAdapters.OrderTableAdapter();
ta.Connection.ConnectionString = myNewConnectionString;

Job done.

Tags:

.Net Framework

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar