Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Connection Strings via a Web Service

The idea of storing connection strings in a data base is a perverse idea, but please hear me out first. We all know that it’s best practice to encrypt connection strings in the web.config file, but what if we just skip the web.config file completely?

A couple of months ago I was asked to move databases from one server to another. This meant having to update connection strings in every program that accessed these various databases. This is the 3rd time in 2 years I’ve had to move databases from one server to another. So I thought of storing connection strings in a database and assigning each a GUID to be accessed via a web service. Instead of placing connection strings in a web.config, you would just need to store the connection string GUID in the web.config, and reference the connection string web service so that you could request that connection string. Encryption can be done at the application level and connection strings are just stored encrypted in the database.

I’ve created a proof of concept and it works fine (its just on a local intranet and not exposed to the internet).

The benefit is obvious to me; such as being able to quickly update connection strings without having to touch the web application. This means that you could build a web application just for editing connection string in the database, that a DBA could use on there own, so they never have to bother a programmer when moving databases.

But the benefit is not what I’m interested in. I’m interested in what everyone here thinks about doing something like this?

like image 566
Adam Avatar asked Mar 30 '09 14:03

Adam


People also ask

How do you read a connection string?

To read the connection string from code, use the ConfigurationSettings class. string connStr = ConfigurationSettings. AppSettings("myConnectionString");

How do I use an IIS connection string?

Open IIS Manager and navigate to the level you want to manage. In Features View, double-click Connection Strings. On the Connection Strings page, click Add in the Actions pane. In the Add Connection String dialog box, type a name for the connection string, such as MyConnection, in the Name text box.

What is a server connection string?

The connection string is an expression that contains the parameters required for the applications to connect a database server. In terms of SQL Server, connection strings include the server instance, database name, authentication details, and some other settings to communicate with the database server.


1 Answers

Take your connection strings out of the main web.config and put them in a separate config file. This file will then be the same for all your apps so if they have to change you just have to copy and paste the same file into all your app folders instead of edit each config separately.

like image 78
Chris Simpson Avatar answered Oct 10 '22 10:10

Chris Simpson