[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 301
  • Last Modified:

Developing locally and deploying remotely - database access

Hi Folks,

I'm pretty new to .Net and am having some issues moving from classic ASP to ASP.Net.  The situation I have is as follows.

I've a domain hosted by 1and1 which includes an MS SQL database.  One of the issues I have is that you cannot link to the DB with a locally installed Enterprise Manager/SSMS, so I'm unable to write a client app that accesses my data on the host.  As such, I need to make a web app that will allow me to carry this out.

I could use ASP but think I need to update my skills somewhat but unfortunately, amongst the multitude of guides and articles I've not found anything that suggests a solution to this specific problem.  Essentially where previously I would make a local copy of the database, develop for that and then change my connection string when uploading I don't know whether that's a) possible or b) appropriate when using .Net.

So, at last, my question is.  If I develop a web app locally can I change the connection string (or equivalent) after deployment on the application server so that it points to the hosted database, and if so, how?

I'd really appreciate it if someone could help or point me in the correct direction.

Oh, and I'm using VS2005 with SQL 2005, and would prefer any code suggestions in VB.Net.


  • 2
3 Solutions
Daniel WilsonCommented:
>>If I develop a web app locally can I change the connection string (or equivalent) after deployment on the application server so that it points to the hosted database, and if so, how?

Your connection string(s) should be going in your web.config file.  As such, changing it/them after deployment is simple -- just deploy a modified web.config.

The web.config file in the root of your asp.net application is an XML file containing configuration aspects for your website. When you connect to a local (SQL Express) database it will create a ConnectionString in the web.config. Providing your database structure is the same in the remote database as it is locally then you can change the connection string in the web.config to point to your remote database with the necessary authentication details.

Attached a code snippet of Local (SQL Express) and Remote connection strings in web.config.

<?xml version="1.0"?>
    Note: As an alternative to hand editing this file you can use the 
    web admin tool to configure settings for your application. Use
    the Website->Asp.Net Configuration option in Visual Studio.
    A full list of settings and comments can be found in 
    machine.config.comments usually located in 
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<!--Local Example-->
<add name="ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
   providerName="System.Data.SqlClient" />
<!--Remote Example-->
		<add name="ConnectionString" connectionString="Data Source=ServerIpOrDomainHere;Initial Catalog=DatabaseNameHere;Persist Security Info=True;User ID=DatabaseUserHere;Password=DatabasePasswordHere;" providerName="System.Data.SqlClient"/>

Open in new window


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now