Multiple Catalog names

Posts   
 
    
Posts: 72
Joined: 11-Aug-2006
# Posted on: 05-Sep-2006 09:45:29   

Hi there

I have trawled the forum a bit & read the documentation at ..

Generated code > Application configuration through .config files

I Have developed a small app using self servicing and I now realise that I need to change the catalog name at runtime ~ i.e. the application is to be run on more than one SQL server database ( the SQL server databases are all the same schemas ) .

Is this possible with self-servicing? If not what is best practive to do this programmatically?

I have close to the latest code ( 3rd August 2006 build )

Thanks heaps for your support.

Marty

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 05-Sep-2006 10:41:24   

Is this application needing the different databases together, or is it like: start the app, pick the db and run the app, end the app ? (assuming it's a desktop app)

Frans Bouma | Lead developer LLBLGen Pro
Posts: 72
Joined: 11-Aug-2006
# Posted on: 05-Sep-2006 23:11:05   

Otis wrote:

Is this application needing the different databases together, or is it like: start the app, pick the db and run the app, end the app ? (assuming it's a desktop app)

Hi Otis

Yes it is a desktop app ASP.NET 2.0 using SQL server 2000 and it needs to use more than 1 database and be able to set programmatically.

Thanks. Marty

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 06-Sep-2006 02:48:49   

You can override the value used in the config file by using DBUtils to set a new connection string. This is from the manual

The DbUtils class lets you set the global connection string to use for every connection to the database. This setting overrides the connection string read from the appSettings section in the .config file. Once the setting is set, every connection to the database uses the set connection string. You set the connection string to use at runtime using the following code:

// C#
DbUtils.ActualConnectionString = "Datasource=myserver;....";
' VB.NET
DbUtils.ActualConnectionString = "Datasource=myserver;...."

If you want to make the application use the connection string defined in the config file again, simply set the ActualConnectionString property to string.Empty.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 06-Sep-2006 09:36:50   

If you want to switch at runtime between databases, you can only do that if the user is the only user using the application, as the connection string is global. If you want runtime-switching between databases, use adapter.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 72
Joined: 11-Aug-2006
# Posted on: 06-Sep-2006 09:58:39   

Otis wrote:

If you want to switch at runtime between databases, you can only do that if the user is the only user using the application, as the connection string is global. If you want runtime-switching between databases, use adapter.

OK sorry just to clarify, There will only be one user of the application.

Also the database name is different for each database - but everything else is the same.

DBUtils.ActualConnectionString didn't seem to work - so is using adapter the only way?

Posts: 72
Joined: 11-Aug-2006
# Posted on: 06-Sep-2006 10:17:55   

[quotenick="bclubb"]You can override the value used in the config file by using DBUtils to set a new connection string. This is from the manual

OK - I got it working using self servicing. I used a combination of DBUtils.ActualConnectionString and overwriting the catalogname overwriting in the config file. <sqlServerCatalogNameOverwrites> <add key="mydefaultcatalog" value="" /> </sqlServerCatalogNameOverwrites>

this works but I guess you then sacrifice the optimization on SQL Server by not having the catalog name there.

It seems odd that you can't do it programmatically at the start of the application - as it must be reading it from the config somewhere.

Thanks Marty

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 06-Sep-2006 10:45:59   

You can't do this in selfservicing, as selfservicing isn't designed to be dynamically using multiple databases at runtime. To clear the name, it will offer you the ability to switch databases at runtime by using a different connection string. Adapter is designer to use multiple db's at runtime.

The catalog name missing in a query won't hurt in sqlserver, as long as you don't have multiple catalogs in your project.

Frans Bouma | Lead developer LLBLGen Pro