A critical issue in a sandbox with stringent timeline for the resolution gives us no way but to debug from dev box without wasting a minute!
While we need to connect to sandbox from dev, the most time taking process and prone to mistakes is updating the web config file being a manual process. As a developer, I never like this process where I need to update each and every parameter.
The solution:
Following Keep It Simply Simple, I made a simple interface for the developer's input (we generally say user's input :p ) where the location of the web config file with its file name to be provided along with 4 connection parameters from LCS.
Below are the 4 connection parameters to be filled from LCS. For more details click this MS link
DataAccess.Database
DataAccess.DBServer
DataAccess.SqlPwd
DataAccess.SqlUser
The file naming convention is <Web config file path + web config file name without extension>
On filling all the details and hitting Ok, the code will update the web config as requested.
So simple and easy right?
Lets understand how to achieve this.
The Detail:
Below is the interface for the developer's input, where the specified controls to be filled accordingly.
For the demo purpose I have a web config file under the webroot folder path with name tryWeb.config, which has the values like below.
​​​​​​​
Now on filling the controls, Ok button needs to be clicked.
I'm passing these values below
Webroot Path: K:\AosService\WebRoot\tryWeb.config
Database Name: New DB Name
DB Server: New DB Server
SQL User Name: New User Name
SQL User Password: New SQL Pass
On hitting OK, web config file will be updated and a success message will appear as shown.
Below is the updated config file.
Instead of searching and updating the parameters manually, a simple Ok click serves the purpose.
With this lot of time can be saved from manual update which can be used for some productive work.
My code just needs the Web config file path along with its name. Suffixing with .xml is also not needed. In a scenario where the name is given wrong, it is handled like below.
If the provided file itself is not found,
Since all fields are equally important, the developer cannot skip any of them.
A warning message will appear if a control is not filled.
​​​​​​​
The Code:
The actual logic is called from Ok button where it is written in clicked method in X++. No external references like DLLs are used here.
My logic in simple terms is,
find the key and update/override its value.
The provided credentials are collected into a string and then segregated as per the Key-Value and if the Key is found then its Value will be updated.
If we have some API which provides the connection related details too, apart from the current LCS API, more automated solution can be made in which only the path will be asked from the developer as an input.
Using C#, a class library can be created which will produce a DLL which eventually can be used as a reference and can be of a different application not linked with F & O. The below code also have the same logic like above.
In this way, web config file can be updated from a program.
Stay Tuned for many new things!
Happy Learning :)