0

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.

dotnetnoob
  • 10,783
  • 20
  • 57
  • 103
  • 1
    Are you using Visual Studio 2010 or 2012? If so you can either specify the remote connection string in the publish profile or create a web.config transform. Either way automates the change for you when you deploy. – tdykstra Jan 04 '13 at 03:36
  • @tdykstra - I'm using 2010 pro – dotnetnoob Jan 04 '13 at 14:55

1 Answers1

1
  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

codingbiz
  • 26,179
  • 8
  • 59
  • 96
  • Thanks for the reply codingbiz. Could you please explain what you mean a little more in the final paragraph. – dotnetnoob Jan 03 '13 at 09:55
  • What I meant is: if want to use remote connection, I would remove _2 from the second connection string and add it to the first. Therefore `ApplicationServices` is always pointing to the right connection that I want. This would happen as you switch between remote and local machine – codingbiz Jan 03 '13 at 10:05