Switching Connection strings

In my app_code folder I create a dataset (customer.xsd). The wizard prompts to create or choose a connection string. Now, I have two strings in my web.config file - one for production machine, one for dev machine. In my code, I DIM a New datatable and a tableadapter for my dataset. I then call the getdata() method that the tableadapter wizard created for me. However, I can find no property for connection.

In VS2003 I used to set an application variable in global.asax.vb that determined which string to use based on Context.Server.MachineName. I could then use that app variable to set the connectionstring property. Can't do that here.

Here is example of code:

Dim dtCustomer As New Customer.CustomerDataTable
Dim taCustomer As New CustomerTableAdapters.CustomerTableAdapter

dtCustomer = taCustomer.GetData()

Handy. But how can I programatically set my connection




Answer this question

Switching Connection strings

  • LoadStore

    .connection is not a member of this type of tableadapter for an .xsd dataset

  • TBrij

    Generated table adapters for strongly typed datasets do have a connection member, but it is set to internal access by default. In the dataset designed, look at the properties of the table adapter. One of the properties is "ConnectionModifier", and it is set to internal. Change it to public and then you will be able to access the connection object for the adapter.
  • chris04920

    Hi!

    Did you try using this following property

    this.taCustomer.Connection.ConnectionString = yourConnectionString;



  • Switching Connection strings