views:

1304

answers:

3

Hello,

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?

+2  A: 

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.

Dominic
A: 

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).

Dominic
A: 

hi Dominic, what does the "Using Query" block mean? im just a newbie here, and i have the same problem with blair

USING is a command that helps tidy things up once you have finished with it. This is from http://msdn.microsoft.com/en-us/library/yh598w02.aspxAs a rule, when you use an IDisposable object, you should declare and instantiate it in a using statement. The using statement calls the Dispose method on the object in the correct way, and (when you use it as shown earlier) it also causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and cannot be modified or reassigned.
Dominic