Question

I'm changing our application from "one set of code & one database" to "one set of code to multiple databases (one database per customer)".

The original code is VS2005 ASP.NET(VB) & lots of XSD's in a separate DLL. The web.config's ConnectionString would override the one stored in the DLL at runtime.

Now I need to change the ConnectionString every time I declare a Data adapter/Dataset/table, because the call could be going to a different database from the last call.

Has anyone got any hints on this?

Was it helpful?

Solution

After a bit of research, it seems that an XSD has a property called ConnectionModifier.

To find it, on your XSD diagram, click the TableAdapter part of the diagram (where the queries are defined).

In the properties window, change ConnectionModifier to Public and click Save. (This seems to change the property for all the Datasets on that page too.)

Back in the main code of your site you can now do something like this:

'declare the adapter as normal
Dim AdapterTest As New DataSetTestTableAdapters.TestTableAdapter

'pass the new connection object into the now visible property
AdapterTest.Connection = New Data.SqlClient.SqlConnection("Data Source=Myserver;Initial Catalog=TEST;Integrated Security=True;")

It only takes a connection object.

I have yet to give this a proper test! Unfortunatley, a new connection object will have to be passed every time you declare something from an XSD.

OTHER TIPS

Also have found that although the property mentioned (ConnectionModifier) is Public, this still can't be seen via code when it is a QueriesTableAdapter. Therefore I had to spend quite a while removing these and replacing them with a normal "Using Query" block.

Also, I'm sure the project seems faster now. It could be the reduction in size or the use of "Using" with all the calls now (the original code was early in our .NET days so could have been written better in the first place).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top