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?
Connection String change at runtime
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
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.
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.