locked
Can't configer the connectionString for asp.net RRS feed

  • Question

  • User-1507580228 posted

    Hello,
    What is the right configration for the ConnectionString in the web config file.
    I have one lie this :

    <connectionStrings>
    <add
    name="RegistrationConnectionString"
    connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Registration.mdf;User Instance=true"
    providerName="System.Data.SqlClient"
    />
    </connectionStrings>

    Which works fine in my Visul Studio 2017.But when I upload it to the Domain It comes up with this Error When the web page try to access it

    (Server Error in '/' Application.
    A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

    Source Error:


    Line 17: {
    Line 18: SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
    Line 19: conn.Open();
    Line 20: string checkuser = "select count (*) from UserData where UserName='" + TextBoxUserName.Text + "'";
    Line 21: SqlCommand com = new SqlCommand(checkuser, conn);


    Source File: g:\pleskvhosts\mytrips100.com\httpdocs\default.aspx.cs Line: 19
    )

    Can anybody help??
    Thank you

    Monday, October 8, 2018 8:31 AM

All replies

  • User-821857111 posted

    You need to check to see if your hosting provider supports SQL Server Express. Many don't. If yours doesn't, they should provide details about how to transfer your database to their system and what connection string to use.

    Monday, October 8, 2018 8:47 AM
  • User1120430333 posted

    Which works fine in my Visul Studio 2017.But when I upload it to the Domain It comes up with this Error When the web page try to access it

    https://docs.microsoft.com/en-us/sql/relational-databases/databases/attach-a-database?view=sql-server-2017

    The link explains how to Attach the detached MDF file to the MS SQL Server database engine, becuase your program is not going to work using an User Instance database. IIS doesn't like User Instance databases, because it  only allows one user to open the database. You have to Attach the MDF file to the database engine so that multiple users using your Web program can access the database concurrently.  The link tells you where the Data directory is located, and you should move the MDF and LDF files to the Data directory and Attach the MDF file to the DB engine using SSMS. 

    You can then remove the AttachDBFilename information off of the connectionstring, after you Attach the MDF file to the DB engine. 

    Monday, October 8, 2018 9:10 AM