Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Wondering if anyone has used a database as a repository of connection strings or app settings that could be use for multiple web applications across multiple different servers?
All of our web api applications have connection strings to logging database and tracing database and I know that in the next 6 months those databases will change location. With out going into each web.config setting I would like to refactor the web services other the next few months to point to a central repository for this connection string (and others).
I try very hard to avoid Machine.config which is why I have the connection string in each web.config.
We are using redis for session management and I thought about using one of the database for this since it's ultimately a key-value pair. Has anyone use it in that matter?
How have some of you gotten past this issue?
As this has been marked as too broad, let me see if I can add more details. We have close to 50 web services that ALL have the same connection string within in the web.config and are located on multiple different servers. I would like to possible edit these services to use a shared resource so that when the connection string changes we would only need to edit a single resource instead of redeploying each web service and/or editing each web.config. I am not a fan of using the machine.config.
While you can perfectly use Redis or any database to store such global settings, maybe what you need is a build script.
If you're in the .NET world, I guess you know what's Team Foundation Server, which also provides Team Foundation Build.
Instead of hardcoding those settings like connection strings, usually you would provide them as custom build properties that can be used to replace some placeholder in your files. Your files would look as follows:
<add name="myConnectionString" connectionString="server=%host%;database=%database%;uid=%user%;password=%password%;" />
Since TFS 2015, TFS Build has a scriptable build system so you can add a Powershell step to replace placeholders with actual values from the build configuration (see this other Q&A to learn more: How to replace multiple strings in a file using powershell).
Once you've replaced the placeholders, you can add a deploy step and deploy the whole application to some machine using FTP, WebDeploy or other protocols.
In summary, maybe your best bet is avoiding hardcoded configurations even in web.config if they might be different depending on the deployment, and these variable settings can be injected using a build script. That is, when you change some configuration, you do it in the build custom properties, and then you deploy your applications again with the configuration changes.
This page should be a good start for you to investigate this approach further: https://www.visualstudio.com/en-us/docs/build/define/build
Also, check Visual Studio Team Services on Azure, a variant of TFS hosted in Azure.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Please, i have a question.
What is optimal way to store some settings and application data like tables or products info of my application localy. That means, data of my program is store on computer where application running.
But, If I want to use or work on this app on other computer it is problem because there aren´t same settings and data. So, I want to work on this app locally on my computer without internet. But, i want to synchoronizing tables and data with other computer if i want to.
I want to develop my personal application on desktop computer. It is like economical applicaton where are lots of products and peoples tables. I choose VS2015 C#.
Thank you very much for any reply.
One way that’s very popular right now is to use SQLite, which leverages the power of sql while being easily contained within your local file system. It’s a popular option used in both desktop and mobile applications currently.
https://www.sqlite.org/index.html - Project site
https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki - ADO.net providers.
Another option is to simply serialize collections of objects and write them to a file. You can then use LINQ (Language Integrated Query), to manage and select the data within your application as desired. However, SQLite would be my first choice.
I would also suggest upgrading to visual studio 2019 unless there are limitations within your system that prevent it. VS2019 is more widely supported by the latest library’s and 3rd party solutions. Many of the newer versions of DotNet, like DotNet Core, will not be supported in VS2015 (Though .net core 2.0 is supported in the 2017 version).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need to develop a standalone windows application that will work offline. I have decided to implement it using C# and WPF.
However because the application database should be able to run without having to install Sql Server on the client's desktop, am not sure what's the best approach.
The concept is that i will develop the application give the executable to the client, install and run the application without any complexity of connecting database.
So far i am considering to use SQLite.
My question is what's the best solution to connect a database within the application.
SqlLite is the best option to go so as to have both the sql features
and also a offline db.
If the data is very, very simple, and you need
it to be readable by other applications or users (with appropriate
permissions), I would probably choose to store it in an XML file or
even a plain-text file inside the user's Application Data folder,
which would be obtained via Environment.GetFolderPath.
If you want to store files such as images,etc then you should go for
IsolatedStorage.
Use EntityFramework to connect to SQLite, my preference is always to use the code-first database so everythings managed from your C# code, I believe EF can be modified to implement INotifyPropertyChanged on your behalf which will help setting up your bindings in WPF.
XML shouldn't be used for anything except for configuration IMHO, it will soon be deprecated in favour of JSON, I'm sure of it, not that that really affects you.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Actually my question is almost similar to this question.
But I have more demands to satisfy.
Actually my web project is developed with ASP.net and C#.And I build it using a tool call "Nant" because I want to install this web project to DotNetNuke(DNN).
So I can create build file using "Nant" tool and then I want to make intallation wizard to host this web project in another computer.
So following demands should be satisfied
I need to install required databases in client computer.
I need to update the connection string in web.config file based the database.
I need to create ODBC connection and save their names in my project config file.
I need to create an application in application pool of IIS.
I need to host my project in IIS.
So question in the link I provided is suggested to use professional edition of advance installer to do this.Actually I have no idea about Advance installer can satisfy all of my demands.
But I want some other solution to do this? Can't I create my own installation wizard by coding? Aren't there any visual studio libraries which can help me?
Please help me.
Thanking you
You can use install shield to do the basic operation. lets go through your steps one by one.
List item installshield has the db folder path and files to move, you can use installshield directory variables to get the path e.g [TARGETDIR]
There is a work around for this, don't put that connection string in webconfig, make a simple text file and put it inside, this may require a little bid code change as well,where you are accessing it. if you dont want to do so read the details after steps.
same as 2,
supported by installed shield
supported by installed shield
Ok Now, for step 2 and step 3, you can also use the webconfig and project file but for this you need to make a console application and parse the files to replace connectionstring etc. Put it under your project and set the target path via installshield of target machine.
this will act like a batch file and you can run it by adding custom actions to your project.
To see how to run any console app or batch follow this
How to run a ".bat" file during installation?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm looking for a way to programmatically determine which version of the .NET Framework an application pool is using in IIS, at runtime, and for a website application to then use that information to choose which *.config file it should use.
Is it possible? I'm not sure where to begin.
I don't know of a good way to do this per application pool. This would be tough to manage, and would easily break when app pools are upgrades are performed, and people wouldn't know why. This isn't generally the way most do this, so I would avoid it if possible. Instead, I suggest the following alternatives:
For development and testing purposes, we use the NConfig library (Install-Package NConfig) to allow for different configurations per hostname.
However, we don't use it in production since we would have to maintain configurations for every server in the web farm, which often are started via automated processes anyway so we don't even know hostnames most of the time. So for managing settings per environment in those cases, we use msdeploy transform configurations. (There are lots of tutorials around the net on how to use those.) It also supports multiple configuration settings via profiles, if you need them.
Also, in your comments you mention something about having to run a installer to install a site that works in .Net 2.0 and 4.0. I'm guessing that means you want your configuration to be different depending which the site is installed on? I would discourage that. It would be easier to get it to install and run in .Net 2.0 (not 4.0) if there are important differences that you can't get to work in both (which would be the better option).
In the end though, there is no 'easy' install for a web site. You have to get the .Net versions (user may not even have 2.0 if they have an old enough Windows :( ), security settings, IIS versions, IIS plugins, often some kind of SQL, connection strings, and so on. If an MSI install of this app is imperative though, then know it's not going to be easy, and you'll most likely need to customize a lot of the process.
You might have enough in looking at the value of property System.Environment.Version
which basically:
Gets a Version object that describes the major, minor, build, and
revision numbers of the common language runtime.
Based on that you can load your config and/or load new application domain with the new configs.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I created an application in C# + WPF + MySQL. What is the best (safest) way to store database connection strings?
Store it on your App.config file and always encrypt it. This link will show you how to encrypt parts of your configuration file.
You could store connections strings in the configuration file. You may secure them if necessary.
Alternatively - the registry. The one place you do NOT store them is the app.config file (whatever.exe.config) as it is only in existence ONCE and the programs folder is not something users can change. Per user settings should never be there.
If the application is running on a server, I'd recommend the machine.config file and encrypt it in the same manor Fernando recommended. If the application is going to be distributed then app.config is where I would store them.
Well I always follows one practice. When ever I do some thing in SL or WPF, I always put Service layer between SL/WPF and database.
You could use the visual studio settings / properties that are available when using visual studio. They are pretty simple to use, and if you use a user setting it is saved in the app data directory for the user, so it is semi-hidden away from tinkering. Then all you'd have to do is some form of encryption to lock it down completely if you so wanted.
I think the best thing about visual studio settings is the ease of use.