Changing catalog with DbUtil.ActualConnectionString

Posts   
 
    
oneillci
User
Posts: 8
Joined: 24-Feb-2009
# Posted on: 11-Jan-2010 12:45:07   

Hi,

Self-servicing with version 2.5.

I have a service running that picks up EDI files sent to us. I now have to cater for files from another territory, so I have a new database on my existing server with a different name but with the exact same schema.

In my service I'm trying to process files from territory 1 first, change my connection and then process files from territory 2 (to go into the new database). At the moment in my dev environment, even though I'm changing the DbUtil.ActualConnectionString, all the records are getting inserted into territory 1 database.

My code is as follows:

string originalConnection = DbUtils.ActualConnectionString;

            // do the processing            
            try
            {
                // Process ROI files first - no need to change connection string here as it should already be ROI db
                ProcessFilesInProcessDirectory(Region.ROI);

                // Now change the connection string so the NI files go into the NI database
                DbUtils.ActualConnectionString = ConfigurationManager.ConnectionStrings["NIConnectionString"].ConnectionString;
                ProcessFilesInProcessDirectory(Region.NI);
            }
            finally
            {
                // Set the connection string back to the original ROI one
                DbUtils.ActualConnectionString = originalConnection;
            }

I had though to change catalogs/connections all that had to be done was to change the connection string, but I'm not having any luck.

Any help is appreciated. Thanks, Ciaran.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 11-Jan-2010 14:45:12   

Please check Catalog name overwriting

Then you can specify an empty string as new name. In that case, the DQE will not specify a catalog name in the generated SQL elements, which will make the SQL target the catalog specified in the connection string.

oneillci
User
Posts: 8
Joined: 24-Feb-2009
# Posted on: 11-Jan-2010 16:09:07   

Thanks!

I had never noticed that part of the documentation before regarding the empty string.

You can also specify an empty string as new name. In that case, the DQE will not specify a catalog name in the generated SQL elements, which will make the SQL target the catalog specified in the connection string.