Catalog Name Overwrites

Posts   
 
    
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 11-Aug-2005 00:19:00   

I am using the catalog name overwriting and have a problem. I have a dataset being used in my data access tier and need to get the re-written string after the overwrite has been done for use with the dataset. Currently I am just reading the connection string from the Web.config file for the dataset, but obviously this is wrong if the catalog name overwrite has been done.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Aug-2005 11:26:52   

how are you using the catalog name overwriting? Through setting an adapter property or using config file settings?

Frans Bouma | Lead developer LLBLGen Pro
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 11-Aug-2005 17:25:42   

Otis wrote:

how are you using the catalog name overwriting? Through setting an adapter property or using config file settings?

I'm using sqlServerCatalogNameOverwrites tag in the config file.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Aug-2005 09:49:42   

tprohas wrote:

Otis wrote:

how are you using the catalog name overwriting? Through setting an adapter property or using config file settings?

I'm using sqlServerCatalogNameOverwrites tag in the config file.

You then could read them using:


NameValueCollection catalogOverwriteDefinitions = (NameValueCollection)ConfigurationSettings.GetConfig("sqlServerCatalogNameOverwrites");
if(catalogOverwriteDefinitions!=null)
{
    for(int i=0;i<catalogOverwriteDefinitions.Count;i++)
    {
        string key = catalogOverwriteDefinitions.GetKey(i);
        string value = catalogOverwriteDefinitions.Get(i);
        if(_catalogOverwrites.ContainsKey(key))
        {
            continue;
        }
        _catalogOverwrites.Add(key, value);
    }
}

(code from sqlserver DQE)

And use it as you want. You can also ask the DQE for the new name if you have the old name: string newName = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.GetNewCatalogName(oldName); which is prefered, as you then don't have to fiddle with the config file settings. If you're using adapter, the best place for this kind of code is in a derived class from DataAccessAdapter, as that class has access to the DQE, so your own code doesn't have to simple_smile

Frans Bouma | Lead developer LLBLGen Pro
tprohas
User
Posts: 257
Joined: 23-Mar-2004
# Posted on: 12-Aug-2005 23:10:05   

This is exactly what I needed I have parsed the connection string and rebuilt it with the new name. If anyone has any suggestions for improving this please post them.

Here is the code that I used for anyone else needing this.


/// <summary>
/// Summary description for WSDataAccessAdapter.
/// </summary>
public class WSDataAccessAdapter : DataAccessAdapter
{
    public WSDataAccessAdapter()
    {
        //
    }

    public override string ConnectionString
    {
        get
        {
            // Get current connection string.
            string connectionString = (string)ConfigurationSettings.AppSettings["Main.ConnectionString"];
            // Parse catalog name fron connection string.
            // database=WS2;
            string oldName = string.Empty;
            Regex regex = new Regex(@"database=\w*;");
            Match match = regex.Match(connectionString);
            // This will always be a match so we don't need to test match.Seccess.
            oldName = match.Value.Replace("database=", "").Replace(";", "");
            string newName = SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.GetNewCatalogName(oldName);
            return connectionString.Replace(oldName, newName);
        }
    }
}