Computer
Computer

Reputation: 2227

Change connection string without rebuild

Generally projects are created using the below method:

Create a solution with 1 DAL class (this has a dbml file). Create a 2nd class project called BLL which is the business layer that creates the CRUD operations. Finally have a Asp .Net project.

First thing i do is in the DAL (Data Access Layer) i create a connection to the database and drag the required tables. I create code to get,edit data etc, in the BLL project. I then have to add a connection string in the Asp .Net project so it can connect to the database.

The issue i always seem to face is when i deploy the project to a test server i can change the Asp .Net projects web.config connection string easily, but at first run the application breaks (cant connect to the sql database) as in the DAL is still looking at the original connection string. So what i have to do is set the new connection string in the DAL project compile and copy that across which then allows everything to work.

I face the same issue when going from the test server to the live server. I've read about using config files but this is as far as i understand they can be used..... But surely there must be an easier way to,change the connection string in one place without having to recompile my DAL dll?

Are there tricks im missing or addons i could use to take advantage of?

Upvotes: 1

Views: 1303

Answers (1)

sevazz
sevazz

Reputation: 9

If you dont want to use 2 connection string(one in web.config of your UI and the other one on your Data Access) and you dont want to depend of a specific database(in this case SQL Server), you can use just a single connection string on your web.config UI.

When you done that, on your DA, just use the DLL Microsoft.Practices.Enterprise.Data so you will not depend of SQL for connections.

Next time, when you want to migrate your application, for example, from SQL to Oracle, since you are not using anymore SQLConnection, you just change your connection string and its done!. Your migration to Oracle its done in 1 minute.

Upvotes: 1

Related Questions