LLBGEn is using wrong database name at run time

Posts   
 
    
ubbara
User
Posts: 3
Joined: 10-Jun-2005
# Posted on: 10-Jun-2005 23:05:49   

I am using LLB Gen Pro 1.0.2004 to do some database stuff in my ASp.NET web project. On my local machine, the database name is Xbert and When I deploy the application to a test server, the name of the database is XbertTest.

WHen I run my application on test server, I get an error saying that "Server user 'xbert' is not a valid user in database 'Xbert'.." I am using XbertTest database not Xbert... as you can see in web..config file. Yes it is true that the name of the database is 'Xbert' on my local machine where I have generated the LLB GEN code.

In my web.config file, I define a property called, <add key="Main.ConnectionString" value="user id=xbert;password=xxx;data source=xxx;initial catalog=XbertTest;" />

This is a sample code of mine that is throwing the error:


DataAccessAdapter adapter = new DataAccessAdapter(ConfigurationSettings.AppSettings["Main.ConnectionString"]);
IRelationPredicateBucket bucket = new RelationPredicateBucket();
//add PermissionDependence PermissionID relation
bucket.Relations.Add(PermissionDependenceEntity.Relations.PermissionEntityUsingPermissionId);
//add UserGroupPermission PermissionID relation
bucket.Relations.Add(PermissionEntity.Relations.UserGroupPermissionEntityUsingPermissionId);
//add MenuItem menuItemID relation
bucket.Relations.Add(PermissionDependenceEntity.Relations.MenuItemEntityUsingMenuItemId);
//where MenuItemID.FileName = @FileName
bucket.PredicateExpression.Add(PredicateFactory.CompareValue(MenuItemFieldIndex.FileName, ComparisonOperator.Equal, FileName));
//AND UsergroupPermission.UserGroupID IN
bucket.PredicateExpression.AddWithAnd(PredicateFactory.CompareRange(UserGroupPermissionFieldIndex.UserGroupId, ADUserGroupsArray));
EntityCollection obj = new EntityCollection(new PermissionDependenceEntityFactory());
adapter.FetchEntityCollection(obj, bucket);

Please help.

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 11-Jun-2005 03:59:31   

Depending on whether you use the Self-Servicing or Adapter scenario, the following information in the documentation can help:

Using the generated code->Adapter->DataAccessAdapter functionality->Connection Strings Using the generated code->Application configuration through .config files

Basically, in order to override the catalog name you don't do it via the connection string, but via one of the above methods. Hope it helps. simple_smile

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 11-Jun-2005 12:46:05   

Thanks Jeff! simple_smile

Frans Bouma | Lead developer LLBLGen Pro
ubbara
User
Posts: 3
Joined: 10-Jun-2005
# Posted on: 13-Jun-2005 15:20:14   

I forgot to mention that I have tried using an overloaded constructor for DataAccessAdapter.

DataAccessAdapter adapter = new DataAccessAdapter(ConfigurationSettings.AppSettings["Main.ConnectionString"]);

The Main.ConnectionString has the entire string defined in the Web.Config file: <appSettings> <add key="Main.ConnectionString" value="user id=xbert;password=xxxx;data source=.;initial catalog=XbertTest;" /> </appSettings>

This did not help.

I do not see a DataAccessAdapter constructor, which accepts the two parameters catalogNameToUse and catalogNameUsageSetting - as said in the documentation. If you have some examples, I will really appreciate it.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 13-Jun-2005 15:34:06   

Your connection string looks like the one for sqlserver, an SqlServer dataaccessadapter does have the constructor for passing in the values:


        /// <summary>
        /// CTor. SqlServer specific
        /// </summary>
        /// <param name="connectionString">The connection string to use when connecting to the database.</param>
        /// <param name="keepConnectionOpen">when true, the DataAccessAdapter will not close an opened connection. Use this for multi action usage.</param>
        /// <param name="catalogNameUsageSetting">SqlServer specific. Configurates this data access adapter object how to threat catalog names in 
        /// persistence information.</param>
        /// <param name="catalogNameToUse">SqlServer specific. The name to use if catalogNameUsageSetting is set to ForceName. Ignored otherwise.</param>
        public DataAccessAdapter(string connectionString, bool keepConnectionOpen, CatalogNameUsage catalogNameUsageSetting, string catalogNameToUse)
        {
            InitClass(connectionString, keepConnectionOpen, catalogNameUsageSetting, catalogNameToUse);
        }

You can also set them in the config file, as discussed in the documentation (DataAccessAdapter functionality in 'using the generated code / adapter ').

Frans Bouma | Lead developer LLBLGen Pro
ubbara
User
Posts: 3
Joined: 10-Jun-2005
# Posted on: 14-Jun-2005 17:07:58   

Thanks guys!. It works

Do you think that the persistence of the catalog name in the generated code, is something that will not be happening in future releases of LLBGEn?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 14-Jun-2005 17:50:22   

It's there for a reason simple_smile -> if you opt for multiple catalogs in your project, there's no conflict. Also, you can have multiple adapters targeting each a different catalog on your server, and you can use one single connection string simple_smile

Frans Bouma | Lead developer LLBLGen Pro
juliom
User
Posts: 17
Joined: 13-Jun-2005
# Posted on: 27-Jun-2005 22:12:38   

Hi there!!!!

I'm having a bit of a problem with the config files... This is how I have the file now...

<?xml version="1.0"?> <configuration> <configSections> <section name="sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler" /> </configSections> <appSettings> <add key="Main.ConnectionString" value="data source=JMURILLO;initial catalog=BusinessProSinc;integrated security=SSPI;persist security info=False;packet size=4096"/> </appSettings> <sqlServerCatalogNameOverwrites> <add key="BusinessProSinc" value="Sinchro"/> </sqlServerCatalogNameOverwrites> </configuration>

As you can see I just kept the original connection string as generated by LLBLGen, and I added the required sections in order to use a different catalog. To be sure this is working I took the original DB, referenced in the connection string, ofline. If I run my code, wich only instantiates an adapter and tries to fetch data into a collection I get an exception. Here is the code I wrote...

 Imports SD.LLBLGen.Pro.ORMSupportClasses
Imports CIS_Solutions.CIS_DBSincronizer.BPSincDBTier.DatabaseSpecific
Imports CIS_Solutions.CIS_DBSincronizer.BPSincDBTier.HelperClasses
Imports CIS_Solutions.CIS_DBSincronizer.BPSincDBTier.FactoryClasses

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim TheAdapter As New DataAccessAdapter
            Dim SomeEntityColl As New EntityCollection(New CHANGES_TLBEntityFactory)

            TheAdapter.FetchEntityCollection(SomeEntityColl, Nothing)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Class

The Exeption I got says

Cannot open database requested in login 'BusinessProSinc'. Login fails. Login failed for user 'RCCADOMAIN\JULIOM'

Am'I missing something???

Thanks a lot....

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 28-Jun-2005 10:19:09   

The user 'RCCADOMAIN\JULIOM' doesn't have access to the database 'Sinchro'. At least that's what I think is the problem.

Frans Bouma | Lead developer LLBLGen Pro
juliom
User
Posts: 17
Joined: 13-Jun-2005
# Posted on: 28-Jun-2005 17:19:48   

Franz:

Otis wrote:

The user 'RCCADOMAIN\JULIOM' doesn't have access to the database 'Sinchro'. At least that's what I think is the problem.

That's not it... 'RCCADOMAIN\JULIOM' has full access to all DB's in that particular server....

It seems to me that is just not replacing the catalog name so keeps of referencing the db used to generate the code.. This of course, if the config file is correct and I think it is... unless you say otherwise...

I'm using LLBLGen 1.0.2004.2 Final Released on April 27th, 2005....

I don't want to do this using the overloads of the DataAdapter constructor cause I think that config files is where this info belongs....

Please, help... confused

JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 29-Jun-2005 00:22:03   

I think I'm having the same or at least very similar problem.

I have two identical SQL Server catalogs. I generate my DAL against "Completions". The other is called "CompletionsLocal". In my application I have set the connection string to point at the latter. In the debugger the adapter is in fact returning that string when I look at the ConnectionString property in the immediate window.

But it's saving the entity to Completions! frowning

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 29-Jun-2005 11:41:10   

juliom wrote:

Hi there!!!!

I'm having a bit of a problem with the config files... This is how I have the file now...

<?xml version="1.0"?> <configuration> <configSections> <section name="sqlServerCatalogNameOverwrites" type="System.Configuration.NameValueSectionHandler" /> </configSections> <appSettings> <add key="Main.ConnectionString" value="data source=JMURILLO;initial catalog=BusinessProSinc;integrated security=SSPI;persist security info=False;packet size=4096"/> </appSettings> <sqlServerCatalogNameOverwrites> <add key="BusinessProSinc" value="Sinchro"/> </sqlServerCatalogNameOverwrites> </configuration>

As you can see I just kept the original connection string as generated by LLBLGen, and I added the required sections in order to use a different catalog. To be sure this is working I took the original DB, referenced in the connection string, ofline. If I run my code, wich only instantiates an adapter and tries to fetch data into a collection I get an exception. Here is the code I wrote...

[...] The Exeption I got says

Cannot open database requested in login 'BusinessProSinc'. Login fails. Login failed for user 'RCCADOMAIN\JULIOM'

Am'I missing something???

Thanks a lot....

Ah, I missed the part in which you took BusinessProSinc offline.

As you specify that as the initial catalog in your connection string, the SqlClient will first connect to that database, then execute the query, which contains references to Sinchro, not businessProSinc. As it can't connect to the BusinessProSinc database, as you took it offline, the connection fails.

Please change the initialcatalog in the connection string to Sinchro.

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 29-Jun-2005 11:43:02   

JimFoye wrote:

I think I'm having the same or at least very similar problem.

I have two identical SQL Server catalogs. I generate my DAL against "Completions". The other is called "CompletionsLocal". In my application I have set the connection string to point at the latter. In the debugger the adapter is in fact returning that string when I look at the ConnectionString property in the immediate window.

But it's saving the entity to Completions! frowning

If you don't specify any name overwrites, it will save in Completions, as that's the name in the catalog persistence information in the generated code. To which catalog you connect through the connection string is not really important, that's just to get access to the server, as you can query any catalog from there you have access to with the user you used to connect to the sqlserver system. (which is the trick behind the multiple catalog feature with a single code base simple_smile )

Frans Bouma | Lead developer LLBLGen Pro
JimFoye avatar
JimFoye
User
Posts: 656
Joined: 22-Jun-2004
# Posted on: 29-Jun-2005 16:25:30   

To which catalog you connect through the connection string is not really important, that's just to get access to the server...

Ok, I was looking at the "Best practises - How do I ... ?" section on where it talks about changing the connection string at runtime by passing it in to the adapter's constructor. Actually, I didn't even do this, I've got it set in the client config file, but reading this I just assumed that the catalog specified in the connection string is the one it would use. Now I'm looking at "Catalog name overwriting" and I assume this is what I need to do to change the catalog.

Helpful suggestion: in that first section maybe put a note that this won't change the catalog, refer to this other section on how to do that? sunglasses

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39615
Joined: 17-Aug-2003
# Posted on: 29-Jun-2005 19:17:26   

Good suggestion, will do simple_smile

Frans Bouma | Lead developer LLBLGen Pro