LLBLGen Connecting to wrong database / catalog ~ .config settings

I used LLBLGen Pro on an old project which needs a few tweeks every so often.  I made some changes the other day but when I was testing my web site it seemed to be connecting to the wrong database.

I couldn’t understand this, the web.config had the correct connection string and I’d never had a problem before.  Changing the connection strings in the web.config as I moved the site from Test to UAT and then Production had always worked fine.

The only difference with this latest test was that I was connecting to a database with a different name on my test machine, it had a different name to the database I’d originally generated the code against.

The LLBLGen code was originally generated against a database , say “ABCD”, and “ABCD” was used on my Test, UAT and Production servers.   I wanted to do some testing but didn’t want to affect my users so I created a new database called, say, “ABCD_TEST”.    I changed the connection string in the web.config to “ABCD_TEST” but the web site was still connecting to “ABCD”.   Why?

By default the generated code will always try to access a database with the same name of the one  it was originally generated against, ignoring any server specified in your  config file.    To get around this problem you have to change the settings in your config to explicitly tell it to ignore it’s default and connect to a different server.

To do this you :

  • Set the database name for Initial Catalog empty.
  • Set CatalogNameUsageSetting to 1.  This forces Llblgen to use a different catalog.
  • Set CatalogNameToUse to the database you want to connect to.

<add key=”Main.ConnectionString” value=”Data Source=server;Initial Catalog=”;Trusted_Connection=true’/>
<add key=”CatalogNameUsageSetting” value=”1″/>
<add key=”CatalogNameToUse” value=”ABCD_TEST” />

This link , from the LLPLGen site provides more information.


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s