Connection String change at runtime

Connection String change at runtime

Postby sc2269 » Mon 18 Oct 2010 16:50

I need to dynamically generate my connection string at runtime since the database that is used is dependent on who is logged into the system. I would like to generate the connection string in its own class... however I have not been able to get any of the Devart design tools to work unless they reference a connection string in web.config or system settings. Is there a way to get the design tools to work and reference a connection string returned in a class/method?

For example I can manually change the generated code to the following.... this works for my executed code but nothing works in Visual Studio at design time (making development more challenging):

Dim conString As clsConnectionString = New clsConnectionString
Me.MySqlConnection1.ConnectionString = conString.GetConnectString(HttpContext.Current.Session("domain"))
Me.MySqlConnection1.Name = "MySqlConnection1"
Me.MySqlConnection1.Owner = Me

Maybe someone has suggestions on another way to do this? Or how to make this work?
sc2269
 
Posts: 1
Joined: Mon 18 Oct 2010 16:44

Postby fritsr » Tue 19 Oct 2010 09:53

Just a suggestion. Can't you just set a connectionstring at designtime that you can use to develop. And than change that connectionstring to whatever you want at runtime ?
fritsr
 
Posts: 22
Joined: Tue 30 Oct 2007 03:49

Postby StanislavK » Tue 19 Oct 2010 14:58

As I can understand, you wish to use at design-time a connection string generated at run-time. Am I correct? This is impossible, at least because your run-time objects (e.g., HttpContext) do not exist before your application is started.

However, you can use the approach suggested by fritsr: perform the design-time configuration with a hardcoded connection string, and then use connection strings returned at run-time in your code.
StanislavK
Devart Team
 
Posts: 1710
Joined: Thu 03 Dec 2009 10:48


Return to dotConnect for MySQL