DB Owner and Database will it always need to be hard coded?

Posts   
 
    
Rainbow
User
Posts: 29
Joined: 23-Feb-2004
# Posted on: 15-Dec-2004 19:26:07   

Hi,

Scenario:

I develop a module for rainbow against my dev database. db owner is e.g. "myaccount" database name is "Rainbow".

Someone installs it but doesn't have access to web.config. Rainbow installer creates the relevant module tables and installs the module.

The issue is where they have a different db owner "theiraccount" and a different database name (e.g. a shared hosting account) "CompanyName".

Even passing the connection string it fails (because the dbo owner is not the same). Now there are ways around it (e.g. You could have a module xml file where they can set db name and owner) but I was wondering if it was possible to not have this in the code (e.g. the PersistenceInfoFactory class)?

Thanks,

John

Rainbow
User
Posts: 29
Joined: 23-Feb-2004
# Posted on: 15-Dec-2004 20:14:06   

Hi,

I thought I had got around it by using the dataadapter constructor and passing connectionstring + SD.LLBLGen.Pro.ORMSupportClasses.CatalogNameUsage.Clear,string.Empty

as well as specifyng whether or not to keep the connection open.

But then I tried using a new account e.g. sa instead of myaccount for the same database and it threw an error :

An exception was caught during the execution of a retrieval query: Invalid object name 'sa.tablename'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

The table owner is myaccount which is why I think it is throwing the error.

So I was still wondering if it was possible running the code without the owner information.

Thanks,

John

Rainbow wrote:

Hi,

Scenario:

I develop a module for rainbow against my dev database. db owner is e.g. "myaccount" database name is "Rainbow".

Someone installs it but doesn't have access to web.config. Rainbow installer creates the relevant module tables and installs the module.

The issue is where they have a different db owner "theiraccount" and a different database name (e.g. a shared hosting account) "CompanyName".

Even passing the connection string it fails (because the dbo owner is not the same). Now there are ways around it (e.g. You could have a module xml file where they can set db name and owner) but I was wondering if it was possible to not have this in the code (e.g. the PersistenceInfoFactory class)?

Thanks,

John

Posts: 46
Joined: 07-Jan-2004
# Posted on: 15-Dec-2004 21:05:07   

Rainbow wrote:

Hi,

I thought I had got around it by using the dataadapter constructor and passing connectionstring + SD.LLBLGen.Pro.ORMSupportClasses.CatalogNameUsage.Clear,string.Empty

as well as specifyng whether or not to keep the connection open.

But then I tried using a new account e.g. sa instead of myaccount for the same database and it threw an error :

An exception was caught during the execution of a retrieval query: Invalid object name 'sa.tablename'.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.

The table owner is myaccount which is why I think it is throwing the error.

So I was still wondering if it was possible running the code without the owner information.

Thanks,

John

Rainbow wrote:

Hi,

Scenario:

I develop a module for rainbow against my dev database. db owner is e.g. "myaccount" database name is "Rainbow".

Someone installs it but doesn't have access to web.config. Rainbow installer creates the relevant module tables and installs the module.

The issue is where they have a different db owner "theiraccount" and a different database name (e.g. a shared hosting account) "CompanyName".

Even passing the connection string it fails (because the dbo owner is not the same). Now there are ways around it (e.g. You could have a module xml file where they can set db name and owner) but I was wondering if it was possible to not have this in the code (e.g. the PersistenceInfoFactory class)?

Thanks,

John

I got arround that problem by putting the llbgen pro connection string in the rainbow config file as another connection string.

i let rainbow do its stuff and then when it gets to my stuff i call the llbgen database. I too have 2 seperate databases one for rainbow and one for my database.

It works....

John Ingram

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Dec-2004 09:40:42   

schema name overwriting for sqlserver will be available soon. At the moment, you can only overwrite the catalog name by using settings in the web.config file or pass it in via the dataaccessadapter constructor (see "DataAccessAdapter functionality" in the Adapter documentation)

Frans Bouma | Lead developer LLBLGen Pro
Rainbow
User
Posts: 29
Joined: 23-Feb-2004
# Posted on: 16-Dec-2004 10:00:31   

Otis wrote:

schema name overwriting for sqlserver will be available soon. At the moment, you can only overwrite the catalog name by using settings in the web.config file or pass it in via the dataaccessadapter constructor (see "DataAccessAdapter functionality" in the Adapter documentation)

Hi,

Looking forward to being able to override the db owner and the catalog name sunglasses but is the db owner always necessary?

At the moment I get a dynamic db owner name and database name by using string manipulation and pulling the current db account and db name from the current connection string (Which lets me support different databases). The only problem comes up when I try to use a differet account from the one used to create the tables (e.g. if I switch from myaccount to sa in the connection string it falls over (since sa isn't the db owner). In a rainbow setup it is rare that you change the db account in the connection string but it is still a possibility.

Any suggestions of how it could be possible to avoid the use of the db owner would be great smile

Thanks for your responses.

John

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Dec-2004 11:31:41   

The schema owner is generated into the persistence information, as we support multiple schemas per catalog for sqlserver, and this will be extended soon to multiple catalogs per project (sqlserver/db2) and multiple schemas per catalog (oracle).

What will be added are presets in the config which say: schema name Foo becomes Bar. Or catalogname Foo becomes Bar. This info will be read once and stored in static vars in the DQE's. In Adapter it is possible to overwrite the catalog name but that's done after the persistence info is read, which is not that inefficient, but it's more efficient to overwrite the name in the sql generator, as there it's needed. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
alexdresko
User
Posts: 336
Joined: 08-Jun-2004
# Posted on: 16-Dec-2004 15:38:21   

Rainbow wrote:

Hi,

Looking forward to being able to override the db owner and the catalog name sunglasses but is the db owner always necessary?

At the moment I get a dynamic db owner name and database name by using string manipulation and pulling the current db account and db name from the current connection string (Which lets me support different databases). The only problem comes up when I try to use a differet account from the one used to create the tables (e.g. if I switch from myaccount to sa in the connection string it falls over (since sa isn't the db owner). In a rainbow setup it is rare that you change the db account in the connection string but it is still a possibility.

Any suggestions of how it could be possible to avoid the use of the db owner would be great smile

Thanks for your responses.

John

Would you mind posting your code that gets the catalog name from the connection string? I need to do the same thing..

On the other hand, my project is currently on hold due to the bug I found in the Infragistics grid (I'm so proud of myself) and I'm still awaiting a fix for that. I could wait for Fran's fix if I have to.

Frans, will the next version completely eliminate the CatalogNameToUse "problem" (for me anyway)?

Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 16-Dec-2004 15:47:26   

alexdresko wrote:

Frans, will the next version completely eliminate the CatalogNameToUse "problem" (for me anyway)? Thanks!

It will be easier to setup. You still have to specify the name to replace an existing name, but it's a bit easier to define that name.

Frans Bouma | Lead developer LLBLGen Pro
Rainbow
User
Posts: 29
Joined: 23-Feb-2004
# Posted on: 19-Dec-2004 16:57:27   

Hi,

Here are the two methods I knocked up to get the values I wanted. These values are needed in the PersistenceInfoBucket construction methods in PersistenceInfoFactory.cs. These methods are shown as is etc etc etc smile I just knocked them up but if you or frans can suggest a better way (Rainbow can support multiple databases off of one codebase which is why I get the connection string dynamically from rainbow [gets the right connectionstring] and then apply these two methods to get the dbo owner and db name. Rainbow uses the db user when creating it's tables etc which is why the user can be used as db owner [Is there a way of getting it straight from the db? which may be a more accurate way]) I'd love to hear it smile .


public static string DatabaseName()
        {
            string database = connectionString;

            int databaseStartCount = database.IndexOf("database");
            if(databaseStartCount == 0)
                databaseStartCount = database.IndexOf("initial catalog");

            database = database.Substring(databaseStartCount);

            databaseStartCount = database.IndexOf("=") + 1;
            int databaseEndCount = database.IndexOf(";");
            database = database.Substring(databaseStartCount,(databaseEndCount-databaseStartCount));

            return database.Trim();
        }

        public static string DatabaseOwner()
        {
            string databaseUser = connectionString;
            int userStartCount = databaseUser.IndexOf("uid");
            if(userStartCount == 0)
                userStartCount = databaseUser.IndexOf("user id");

            databaseUser = databaseUser.Substring(userStartCount);

            userStartCount = databaseUser.IndexOf("=") + 1;
            int userEndCount = databaseUser.IndexOf(";");
            databaseUser = databaseUser.Substring(userStartCount,(userEndCount-userStartCount));
            return databaseUser.Trim();
        }

alexdresko wrote:

Rainbow wrote:

Hi,

Looking forward to being able to override the db owner and the catalog name sunglasses but is the db owner always necessary?

At the moment I get a dynamic db owner name and database name by using string manipulation and pulling the current db account and db name from the current connection string (Which lets me support different databases). The only problem comes up when I try to use a differet account from the one used to create the tables (e.g. if I switch from myaccount to sa in the connection string it falls over (since sa isn't the db owner). In a rainbow setup it is rare that you change the db account in the connection string but it is still a possibility.

Any suggestions of how it could be possible to avoid the use of the db owner would be great smile

Thanks for your responses.

John

Would you mind posting your code that gets the catalog name from the connection string? I need to do the same thing..

On the other hand, my project is currently on hold due to the bug I found in the Infragistics grid (I'm so proud of myself) and I'm still awaiting a fix for that. I could wait for Fran's fix if I have to.

Frans, will the next version completely eliminate the CatalogNameToUse "problem" (for me anyway)?

Thanks!