locked
unable to open web pages in asp.net project RRS feed

  • Question

  • User-945256609 posted

    Dear all,

    I am using my old asp.net project in my laptop after a long time. Now it is not connecting to DB from web pages.

    I am getting the following error

    A network-related or instance-specific error occurred while establishing a connection to SQL Server.

    When I test it with UDL file the connection establishes with user name and password and it succeeds.

    My web.config file is given below.

    <?xml version="1.0"?>
    <!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=169433
    -->
    <configuration>
    <connectionStrings>
    <add name="ContactConnectionString" connectionString="Data Source=hp-home-laptop;Initial Catalog=Contact;User ID=IFMRSys;Password=Wanna@123" providerName="System.Data.SqlClient"/>
    <add name="DBCS" connectionString="Data Source=hp-home-laptop;Initial Catalog=Contact;User ID=IFMRSys;Password=Wanna@123" providerName="System.Data.SqlClient"/>
    <add name="SampleConnectionString" connectionString="Data Source=hp-home-laptop;Initial Catalog=Contact;User ID=IFMRSys;Password=Wanna@123" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
    <compilation debug="true" targetFramework="4.0">
    <assemblies>
    <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    </assemblies>
    </compilation>
    <authentication mode="Forms">
    <forms loginUrl="~/content/Login/LoginPage.aspx" defaultUrl="~/content/pages/Welcome.aspx"/>
    </authentication>
    <authorization>
    <deny users="?"/>
    <!--<deny users="?"/>-->
    </authorization>
    <customErrors mode="Off"/>
    </system.web>
    <location path="~/content/Login/LoginPage.aspx">
    <system.web>
    <authorization>
    <allow users="*"/>
    </authorization>
    </system.web>
    </location>
    <location path="~/content/pages/Welcome.aspx">
    <system.web>
    <authorization>
    <allow users="*"/>
    </authorization>
    </system.web>
    </location>
    <!--<system.webServer>
    <defaultDocument>
    <files>
    <clear />
    <add value="~/content/pages/Welcome1.aspx" />
    </files>
    </defaultDocument>

    </system.webServer>-->
    </configuration>

    can somebody help me on this question

    Wednesday, March 20, 2019 1:23 PM

Answers

All replies

  • User-1038772411 posted

    Your connection string was probably overriden when you copied your new website version on the server. Please check the connection string in web.config and see if it is valid.

    Wednesday, March 20, 2019 1:31 PM
  • User-945256609 posted

    I have the files which is available locally on my system. I am checking the pages from Visual Studio solution by right clicking the pages for browser reading. I know we can check connection options through udl file. is there any other method you can explain step by step.

    Many thanks for your reply.

    Wednesday, March 20, 2019 1:42 PM
  • User475983607 posted

    Right click the UDL file and open it in notepad.  Compare the UDL connection string to the web.config.

    <connectionStrings>
    	<add name="ContactConnectionString" connectionString="Data Source=hp-home-laptop;Initial Catalog=Contact;User ID=***;Password=****" providerName="System.Data.SqlClient"/>
    	<add name="DBCS" connectionString="Data Source=hp-home-laptop;Initial Catalog=Contact;User ID=****;Password=****" providerName="System.Data.SqlClient"/>
    	<add name="SampleConnectionString" connectionString="Data Source=hp-home-laptop;Initial Catalog=Contact;User ID=***;Password=****" providerName="System.Data.SqlClient"/>
    </connectionStrings>

    Another approach is using Visual Studio to connect to the DB then copy the connection string from the properties window.

    SQL Server Object Explorer 

    https://docs.microsoft.com/en-us/sql/ssms/object/open-and-configure-object-explorer?view=sql-server-2017

    Server Explorer

    https://support.microsoft.com/en-us/help/316649/how-to-use-the-server-explorer-in-visual-studio-net-and-visual-studio

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 20, 2019 3:26 PM
  • User-945256609 posted

    I had compared the udl file and live version. I found the instance name hp-home-laptop/sqlexpress  - /sqlexpress was missing.

    I just added the instance name /sqlexpress and the page started to be visible.

    many thanks

    Sathya

    Wednesday, March 20, 2019 4:46 PM