Question

I have a Web application (website) that uses an SQL Server database.

I plan on creating anumber of clone sites so want to place the database in its own folder, outside of the main project folder.

It's the first time I've deployed a web application, so I have a couple of questions.

1) Is locating the database outside the project an acceptatble way of sharing the database?

2) The connection string will be different between my local machine and remote machine. The remote has Sql2008 Web Edition and my local machine SQL Server Express. Also the directory structure will be different as its not virtual. Is these anything I can do to automate this or is is purely a manual fiddle?

Thanks in advance.

Was it helpful?

Solution

  1. If you don't want the database to be tied to a project, then you need a central place where it can be accessed by other projects/sites

  2. Use a connection string stored in a central place e.g. Web.Config of each web application. You could create multiple connection string with different names pointing to different database source e.g. RemoteConnection and LocalConnection.

Example

<add name="ApplicationServices"
     connectionString="Local DB"
     providerName="System.Data.SqlClient" />

<add name="ApplicationServices_2"
         connectionString="Remote DB"
         providerName="System.Data.SqlClient" />

When changing between local server and remote server, make sure the right connection has the name "ApplicationServices" and you won't need to change your code

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top