Override Catalog Name using non-config method

Posts   
 
    
uniblab
User
Posts: 4
Joined: 15-Jan-2009
# Posted on: 16-Jan-2009 00:54:28   

Hello: I have a class library that does not use an app.config file. Therefore, I am not able to use the config file method to override the catalog name of the connection string. There is an alternative method that is talked about in the user manual here:

http://www.llblgen.com/documentation/2.6/hh_start.htm

I believe I have the first part down with the following:

Dim mHashTable As New SD.LLBLGen.Pro.ORMSupportClasses.CatalogNameOverwriteHashtable(2)

It then says:

The created CatalogNameOverwriteHashtable is then passable to the DataAccessAdapter constructor or you can set the CatalogNameOverwrites properties to an instance of this special hashtable.

I am unclear on how to do this. Could anyone provide an example of the code that accomplishes this?

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 16-Jan-2009 11:15:36   
            CatalogNameOverwriteHashtable newCatalogName= new CatalogNameOverwriteHashtable();
            newCatalogName.Add("OldCatalogName", "NewCatalogName");

Then pass that to the DataAccessAdapter Ctor.

uniblab
User
Posts: 4
Joined: 15-Jan-2009
# Posted on: 16-Jan-2009 20:29:52   

Walaa: Thanks for the quick reply. What dll is the DataAccessAdapter contained in? I see in the reference manual it says:

UnitTests.Dal.Adapter.DatabaseSpecific.DataAccessAdapter

Is there a UnitTests.LLBLGen.Pro.dll?

uniblab
User
Posts: 4
Joined: 15-Jan-2009
# Posted on: 16-Jan-2009 22:17:02   

Walaa: I am using the self servicing version. It looks like the dll I need is: UnitTests.Dal.AdapterDBSpecific.dll Is this only relevant to the Adapter version or is there still some way for me to do this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 17-Jan-2009 07:31:10   

uniblab wrote:

Walaa: I am using the self servicing version. It looks like the dll I need is: UnitTests.Dal.AdapterDBSpecific.dll Is this only relevant to the Adapter version or is there still some way for me to do this?

Oh, SelfServicing, then you should go on the DBUtils functionality way.

David Elizondo | LLBLGen Support Team
uniblab
User
Posts: 4
Joined: 15-Jan-2009
# Posted on: 20-Jan-2009 18:01:53   

I have tried the following:

DAL.HelperClasses.DbUtils.ActualConnectionString = "data source=data_source_name;initial catalog=initial_catalog_name;password=actual_password;persist security info=True;connect timeout=420;user id=user_id;packet size=4096"

I have also tried:

DAL.HelperClasses.DbUtils.ActualConnectionString = String.Empty

DAL.HelperClasses.DbUtils.ActualConnectionString = "data source=data_source_name;initial catalog=initial_catalog_name;password=actual_password;persist security info=True;connect timeout=420;user id=user_id;packet size=4096"

It does not change the catalog name it only changes the username and password.

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 21-Jan-2009 10:59:29   

You should also use the sqlServerCatalogNameOverwrites in the config file, but set the new catalog name to an empty string, then the one you pass to the DbUtils.ActualConnectionString will be used.

<sqlServerCatalogNameOverwrites>
    <add key="OldNameCatalog1" value="" />
</sqlServerCatalogNameOverwrites>
joshrivers
User
Posts: 10
Joined: 30-Dec-2008
# Posted on: 22-Jan-2009 00:43:32   

This also seems to work for self-service:


 public static class OverrideCatalogs
    {
         public static void OverrideCatalog(string initialCatalogName, string overrideName)
        {
            var overrides = GetOverwritesDictionary();
            if (!overrides.ContainsKey(initialCatalogName))
            {
                overrides.Add(initialCatalogName, overrideName);
            }
            else
            {
                overrides[initialCatalogName] = overrideName;
            }
        }

        public static Type GetDynamicQueryEngineType()
        {
            DynamicQueryEngine obj = new DynamicQueryEngine();
            return obj.GetType();
        }

        public static Dictionary<string, string> GetOverwritesDictionary()
        {
            var obj = GetDynamicQueryEngineType().InvokeMember("_catalogOverwrites", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Static, null, null, null);
            return obj as Dictionary<string, string>;
        }

        public static void ClearOverrides()
        {
            GetOverwritesDictionary().Clear();
        }
    }

Although it's certainly naughty.

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 15-Nov-2009 13:33:11   

Walaa wrote:

You should also use the sqlServerCatalogNameOverwrites in the config file, but set the new catalog name to an empty string, then the one you pass to the DbUtils.ActualConnectionString will be used.

<sqlServerCatalogNameOverwrites>
    <add key="OldNameCatalog1" value="" />
</sqlServerCatalogNameOverwrites>

Hi.

Its been a long time.

I have adopted the setting of connection string as documented in 'Using Generated Code' --> 'Application Configuration through .Config File' --> Catalog name overwriting.

However, perhaps I am missing something, but when I 'call' a stored procudure, DBUtils.CallRetrievalStoredProcudure does not 'seem' to 'like' errors as it cannot find the 'old' catalogue name.

Note: I am using Self Service.

Help!

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 16-Nov-2009 08:14:16   

Hi Suresh,

Did you set the new catalog name in the connection string?

If the answer is yes, which runtime library version are you using?

sparmar2000 avatar
Posts: 341
Joined: 30-Nov-2003
# Posted on: 16-Nov-2009 15:03:41   

Hi Walaa

LLBL is indeed doing what it says on the box i.e. as documented in Using Generated Code --> Application Configuration through .Config File --> Catalog name overwriting.

I have now discovered that the issue is hard coding of the catalogue name in the Store Procedure and am getting that changed.

Thanks for your help.