Changing ConnectionString at runtime

Posts   
 
    
OleHec
User
Posts: 4
Joined: 01-Sep-2005
# Posted on: 15-May-2009 08:10:10   

I'm using LLBLGen Pro version 2.6 on MSSQL 2005 and 2008

I have a windows form where the users can select which database they want to connect to. After selection I need to change the ConnectionString on Adapters like this static one

public static class MyClass { private static readonly DataAccessAdapter _Adapter = new DataAccessAdapter(); .. public static void FetchSomething() { ... _Adapter.FetchTypedList(... } }

I've tried _Adapter.CloseConnection(); _Adapter.ConnectionString= newConnectionString; _Adapter.OpenConnection(); MyClass.FetchSomething()

but that doesn't work, it fetches using the old ConnectionString.

What can I do ?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-May-2009 09:17:53   

Are these databases reside in the same server instance but with different catalog names, or they have the same catalog name, but in different server instances?

OleHec
User
Posts: 4
Joined: 01-Sep-2005
# Posted on: 15-May-2009 09:19:18   

They can be at different servers

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-May-2009 09:20:29   

but same catalog name...right?

OleHec
User
Posts: 4
Joined: 01-Sep-2005
# Posted on: 15-May-2009 09:25:08   

No, both database name and server can be different. Ser can also be MSSQL 2005 or 2008

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 15-May-2009 09:42:44   

Since caalog names can be diffreent, then you should use Catalog name overwrites. And you should 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