Connection strings

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
aspmaker_fan
User
Posts: 46

Connection strings

Post by aspmaker_fan »

Hi

I think the connection strings are stored in the compiled exe file. How do we change the connection strings after combiled and published? Or is there any way we could dynamically change the connection strings for multi tenant and multi user system? (v2017).

Thanks
Zam


Webmaster
User
Posts: 9425

Post by Webmaster »

Use Database_Connecting server event, see Server Events and Client Scripts in the help file.


aspmaker_fan
User
Posts: 46

Post by aspmaker_fan »

Hi,

Many thanks. The script below works. How we can use different connection strings based on logging in user? I meant dynamically set the connection string? or is there any way of doing this such as using session ids?

// Database Connecting event
public virtual void Database_Connecting(ref string Connstr) {

        System.Configuration.Configuration rootWebConfig =
        System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot");
        System.Configuration.ConnectionStringSettings connString;
        if (rootWebConfig.ConnectionStrings.ConnectionStrings.Count > 0)
        {
            connString =
                rootWebConfig.ConnectionStrings.ConnectionStrings["Northwind"];
            if (connString != null)
                ew_Response.Write(connString.ConnectionString);
            else
                ew_Response.Write("No Northwind connection string");

            Connstr = connString.ConnectionString;

        }

Post Reply