Web app access to the MS SQL Database works when debugging localhost but doesn't work once deployed to local IIS7 web server

Posted on 2011-04-21
Last Modified: 2012-05-11
I've created a web application in ASP.NET with VB.NET as the code-behind using Visual Studio 2010. The web application is connected to a MS SQL Server 2005 database on a remote web server on the company's intranet. When I run the application as localhost through Visual Studio 2010 everything works fine, I'm able to login to the website, and access data within the database from the website, as well as insert data in to the database via the web form.

The problem is once I deploy this web application to my local web server set up with IIS 7, and try to browse the site, the site comes up, but anything on the site related to accessing the MS SQL database (ex. inserting data through form, loginng in to access protected pages) is not functional. And the browser does not return any kind of error whatsoever.

Please help,
Question by:rmitwiz
    LVL 30

    Expert Comment

    What are your security settings in the connectionstring to the database? Are you using SQL authentication or Windows authentication?

    Are there database management tools e.g. SQL Server Management Studio on the web server - are you able to connect to the database from this server using SSMS?

    Errors not showing on the interface might be due to how you are handling your exceptions. What are you doing with the exceptions in your Try...Catch blocks?
    LVL 1

    Author Comment

    My connection string is as follows:
    <add name="ConnectionStringpforms" connectionString="Data Source=servername; Initial Catalog=DatabaseName; Integrated Security=True" providerName="System.Data.SqlClient" />

    Yes, I am able to connect to the database from the server using SSMS.

    And I do not have any Try...Catch Blocks in my code.
    And keep in mind everything works perfectly  on localhost. Just not once the web application is deployed to my local machine's IIS7 web server.
    LVL 30

    Accepted Solution

    "Integrated Security=True" means you are running the application with windows authentication. Now, when you run on your machine, you are using a different account to the one being used by the web server to log onto the database. The web server will use the account under which IIS or more specifically, the account under which the application pool is running.

    "Yes, I am able to connect to the database from the server using SSMS." that tells us that a connection to teh sql server is possible from the web server box. That eliminates network and firewall configurations etc etc.

    To cut a long story short, I would recommend SQL Server authentication. Either use the "sa" account, or preferably, create a SQL account for your application with access to the database in question and setup your connection string to use that account.

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Suggested Solutions

    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now