sqlServerCatalogNameOverwrites at runtime

Posts   
 
    
Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 22-Apr-2008 17:30:44   

Is there a way to do the following at runtime?

<sqlServerCatalogNameOverwrites> <add key="WeldQA" value="WeldQADev" /> </sqlServerCatalogNameOverwrites>

Having this in the app.config file is not ideal as the Catalog Name of the database is dependant on the command line argument passed in. As an example to tell the program to use the production, development, or testing version of the database.

Thanks!

Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 22-Apr-2008 17:39:47   

More info....

LLBLGen Pro 2.5 and the gen. project is Self Serve.

I was also reading a post:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=8785

Where a poster had mentioned:

"I have set the "value=" part in the "sqlServerCatalogNameOverwrites" section to an empty string; now I can switch to any other sqlserver database at runtime by changing the catalog name in the connectionstring. My problem is solved, sorry for the inconvenience. "

Is this a best practice to solve this problem? Essentially I am having to specify the sqlServerCatalogNameOverwrites key to equal the name of the Catalog in the connection string anyway.

What's the advantage of having the catalog name tightly bound in with the columns and other code in the generated classes? Is there a reason for this that I am missing? In any other .NET project I've written, changing the connection string does not require changing the catalog names anywhere else in your code.

Thoughts?

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 22-Apr-2008 19:03:17   

That's is the best practice to do what you are trying to do (changing the catalog name at runtime). The catalog name is used in the generated code for write the queries against DB: SELECT * FROM [SCHEMA/OWNER].[CATALOG_NAME].[TABLE_TAME]....

Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 22-Apr-2008 19:10:59   

So you mean just setting the value in the config file to "" and assigning the ConnectionString at run time?

What advantage does having the InitialCatalog name hard coded in the ORM generated files was my other question... Any idea?

Select * from tblMyTable works the same as Select * from myCatalog.tblMyTable

I'm going to assume that this is for those cases where your ORM project has more than one catalog?

Dan1
User
Posts: 41
Joined: 20-Sep-2007
# Posted on: 22-Apr-2008 19:11:19   

So you mean just setting the value in the config file to "" and assigning the ConnectionString at run time?

What advantage does having the InitialCatalog name hard coded in the ORM generated files was my other question... Any idea?

Select * from tblMyTable works the same as Select * from myCatalog.tblMyTable

I'm going to assume that this is for those cases where your ORM project has more than one catalog it uses within the same project?

goose avatar
goose
User
Posts: 392
Joined: 06-Aug-2007
# Posted on: 22-Apr-2008 19:39:31   

So you mean just setting the value in the config file to "" and assigning the ConnectionString at run time?

If you are using SelfServicing you could use DBUtils.ActualConnectionString at runtime (http://llblgen.com/TinyForum/Messages.aspx?ThreadID=13082)

What advantage does having the InitialCatalog name hard coded in the ORM generated files was my other question... Any idea?

It's best practice to write SQL statements using Fully Qualified Names as it gains performance.