Developer forum

Forum » Development » SQL settings from GlobalSettings

SQL settings from GlobalSettings

Søren Ravn Lund
Reply

Hello,

I am trying to find a notification subscriber that triggers before Dynamicweb loads the SQL information (sql server, database, user/password) from GlobalSettings.aspx.

So far unsuccesfull, I have tried the subscribers from here but it seems that none of them actually happens before the SQL settings already is loaded into Dynamicweb's memory.

Do you know of a way to hook into the application before the SQL settings is loaded from GlobalSettings?

 


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

What are you trying to accomplish? Maybe there are other ways to do what you need to do. Are you trying to overrride the connectioninfo?

Votes for this answer: 1
 
Søren Ravn Lund
Reply

I am trying to control the SQL connection string from the Web.Config so I can setup my VS builds to configure the connection string depending on the build I want (e.g. development, staging or live).

My problem has been that Dynamicweb.Configuration.SystemConfiguration.Instance was initilialized before I had a chance to edit GlobalSettings.

I found out that calling Dynamicweb.Configuration.SystemConfiguration.Reset() after I edit GlobalSettings in code with the BeforeStart subscriber accomplishes what I want, since then it re-reads the globalsettings with the updated settings.

 

I will marked your reply as the answer since I found a solution :-)

 
Søren Ravn Lund
Reply
This post has been marked as an answer

I found a cleaner way of accomplishing what I wanted without the use of subscribers.

 

    public class DatabaseConnectionProvider : IDatabaseConnectionProvider
    {
        public IDbConnection CreateConnection()
        {
            var connectionString = ConfigurationManager.ConnectionStrings["MyDb"].ConnectionString;
            IDbConnection connection = new SqlConnection(connectionString);
            connection.Open();
            return connection;
        }

        public IDbDataAdapter CreateAdapter()
        {
            return new SqlDataAdapter();
        }
    }

Votes for this answer: 2

 

You must be logged in to post in the forum