Switching database catalogs

Posts   
 
    
Ilija
User
Posts: 5
Joined: 11-Jun-2008
# Posted on: 11-Jun-2008 15:51:12   

Hey guys,

I have a question about programmatically switching catalogs for the LLBL generated code.

We have an admin database and any number of uniquely named user databases(which may or may not end up being on a different server) and I would like to know what is the best way to switch between catalogs?

I attempted it with this code, but I got an exception:


            TasksEntity task = new TasksEntity();
            task.AccountId = View.AccountID;
            task.UserId = View.UserID;
            task.TaskTypeId = 1;
            task.TaskStatusId = 1;
            task.Note = _list.MailingListFriendlyName;

            CatalogNameOverwriteHashtable changeme = new CatalogNameOverwriteHashtable();
            changeme.Add("Administration_PubV7_Main", _schemaName);
            SchemaNameOverwriteHashtable schemachange = new SchemaNameOverwriteHashtable();
            schemachange.Add("dbo", "dbo");
            using (DataAccessAdapter da = new DataAccessAdapter(strConn, false, changeme, schemachange))
            {
                da.SaveEntity(task);
            }

Here's the exception:


The element name 'TasksEntity' isn't known in this provider
Parameter name: elementName

And the stack trace:


"   at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceInfoProviderBase.GetElementMappingInfo(String elementName)
   at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceInfoProviderBase.GetAllFieldPersistenceInfos(String elementName)
   at SD.LLBLGen.Pro.ORMSupportClasses.PersistenceInfoProviderBase.GetAllFieldPersistenceInfos(IEntity2 entity)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.GetFieldPersistenceInfos(IEntity2 entity)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse)
   at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave)
   at BlueSkyFactory.Publicaster7.Public.Presenter.ListManagerPresenter.ImportList(Stream File, String PrimaryKeyField, String Action, String FileType, String Delimiter, IMainView View) in D:\\Publicaster7\\Publicaster7\\Public\\BlueSkyFactory.Publicaster7.Public.Presenter\\Classes\\ListManagerPresenter.cs:line 367
   at BlueSkyFactory.Publicaster7.CI.List.Controls.wucListImport.btnUploadFile_Click(Object sender, EventArgs e) in D:\\Publicaster7\\Publicaster7\\Public\\WebUI\\BlueSkyFactory.Publicaster7.CI\\List\\Controls\\wucListImport.ascx.cs:line 87
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)"

We are using LLBLGen Pro v2.5 final and SQL Server 2005 Enterprise.

Any help would be greatly appreciated.

Thanks, Ilija

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 11-Jun-2008 16:08:35   

The following thread might be relevant to your question, please read it to end. http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=12045

Ilija
User
Posts: 5
Joined: 11-Jun-2008
# Posted on: 11-Jun-2008 16:22:37   

Thanks Walaa, I read through that thread and tried this:


            TasksEntity task = new TasksEntity();
            task.AccountId = View.AccountID;
            task.UserId = View.UserID;
            task.TaskTypeId = 1;
            task.TaskStatusId = 1;
            task.Note = _list.MailingListFriendlyName;

            using (DataAccessAdapter da = new DataAccessAdapter(strConn, false, CatalogNameUsage.ForceName, _schemaName))
            {
                da.SaveEntity(task);
            }

But I still get the same exception... Do you think the problem might be something else?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 11-Jun-2008 17:25:18   

We have an admin database and any number of uniquely named user databases

Does the TaskEntity belong to the admin database or a user specific database.

(which may or may not end up being on a different server)

In this case, are they on the same server?

Ilija
User
Posts: 5
Joined: 11-Jun-2008
# Posted on: 11-Jun-2008 17:30:45   

Ah sorry, I should have specified that. TaskEntity belongs to the admin database.

Yes they are on the same server right now, but we would like to be prepared for when we do decide to split them up.

I should also note that we have LLBL generated code working fine in other areas of our application, it's just that we are looking for the best way to do the database switching with LLBL.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Jun-2008 03:57:30   

Ilija wrote:

Ah sorry, I should have specified that. TaskEntity belongs to the admin database.

If the TaskEntity doesn't belong to user-specific catalog (only admin catalog) I think that's why you get that error when you try to save a TaskEntity object at the re-directed database (the user-specific one). So I don't understand what are you really trying to do disappointed

Ilija wrote:

CatalogNameOverwriteHashtable changeme = new CatalogNameOverwriteHashtable(); changeme.Add("Administration_PubV7_Main", _schemaName);

What is the value of the _schemaName variable?

David Elizondo | LLBLGen Support Team
Ilija
User
Posts: 5
Joined: 11-Jun-2008
# Posted on: 12-Jun-2008 16:19:44   

Ah sorry about that, I had the switch backwards. The connection string(strConn) points to an account database, and I need to switch it over to the admin database.

The _schemaName string contains the name of the current account database.

I tried this:


            using (DataAccessAdapter da = new DataAccessAdapter(strConn, false, CatalogNameUsage.ForceName, "Administration_PubV7_Main"))
            {
                da.SaveEntity(task);
            }

And this:


            CatalogNameOverwriteHashtable changeme = new CatalogNameOverwriteHashtable();
            changeme.Add(_schemaName, "Administration_PubV7_Main");

            SchemaNameOverwriteHashtable schemachange = new SchemaNameOverwriteHashtable();
            schemachange.Add("dbo", "dbo");
            using (DataAccessAdapter da = new DataAccessAdapter(strConn, false, changeme, schemachange))
            {
                da.SaveEntity(task);
            }

But neither of them seem to work, I get the same exception... I'm starting to think that this is not an issue with catalog switching, but maybe with something else. What do you guys think?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 13-Jun-2008 09:33:14   

You need to use a Catalog name overwriting in the config file as follows:

<sqlServerCatalogNameOverwrites>
    <add key="AdminCatalogName" value="" />
    <add key="UserCatalogName" value="" />
</sqlServerCatalogNameOverwrites>

Notes: 1- Don't forget the configSections part. 2- replace the AdminCatalogName and UserCatalogName with the real names of the catalogs you used for code generation.

At runtime (and since both databases can exists in different servers): When connecting to the Admin catalog, you should pass the exact connection string of the Admin database to the DataAccessAdapter CTor. Same thing should be done when connecting to a UserDatabase.

Ilija
User
Posts: 5
Joined: 11-Jun-2008
# Posted on: 13-Jun-2008 21:47:03   

Hey guys,

Sorry to waste your time but I figured it out. We have 2 LLBL projects, one for each database, and I was simply using the DataAccessAdapter from the wrong namespace.

Thanks for all the help, I can't believe it was something so simple smile