سؤال

I have a asp .net 2.0 web application. It works fine on my local machine. I published the website to my hosting provider but it gives the following error:

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)

The settings in my web.config file is as follows:

 <membership>
  <providers>
    <clear/>
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" passwordAttemptWindow="10" passwordStrengthRegularExpression=""/>
  </providers>
</membership>

and

<add name="classifiedsConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CLASSIFIEDSDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

All mdf ldf files are uploaded to the host.I have checked many similar questions on stackoverflow but the solutions didnt help me. Is it wrong to use sqlexpress in this way ? how can i fix this problem ?

Any helps would be appreciated. thanks Thanks.

Edit:

There is no LocalSQLServer connection string in web.config file. But to make sure i tried adding this connection string

<add name="LocalSqlServer" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>

but the result didnt change.

Edit2:

I updated the connectionstrings of the providers and now my web.config file is as follows:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <location path="Admin">
    <system.web>
      <authorization>
        <allow roles="Administrators"/>
        <deny users="*"/>
      </authorization>
    </system.web>
  </location>
  <location path="PostAd.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <location path="EditPhotos.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <location path="MyAds.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <location path="MyProfile.aspx">
    <system.web>
      <authorization>
        <deny users="?"/>
      </authorization>
    </system.web>
  </location>
  <system.web>
    <customErrors mode="Off"/>
    <pages styleSheetTheme="Red"/>
    <authentication mode="Forms"/>
    <membership>
      <providers>
      <clear/>
      <add name="AspNetSqlMembershipProvider"
           type="System.Web.Security.SqlMembershipProvider, System.Web,     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
           connectionStringName="membershipConnection"
           enablePasswordRetrieval="false"
           enablePasswordReset="true"
           requiresQuestionAndAnswer="true"
           applicationName="/"
           requiresUniqueEmail="true"
           passwordFormat="Hashed"
           maxInvalidPasswordAttempts="5"
           minRequiredPasswordLength="7"
           minRequiredNonalphanumericCharacters="1"
           passwordAttemptWindow="10"
           passwordStrengthRegularExpression=""/>
    </providers>
    </membership>
    <profile enabled="true">
      <properties>
        <add name="FirstName" type="System.String"/>
        <add name="LastName" type="System.String"/>
        <add name="MemberId" defaultValue="0" type="System.Int32"/>
        <group name="Core"/>
      </properties>
    </profile>
    <roleManager enabled="true"/>
    <compilation debug="true"/>
    <siteMap defaultProvider="RoleEnabled_AspNetXmlSiteMapProvider" enabled="true">
      <providers>
        <clear/>
        <add name="RoleEnabled_AspNetXmlSiteMapProvider" type="System.Web.XmlSiteMapProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" siteMapFile="web.sitemap" securityTrimmingEnabled="true"/>
      </providers>
    </siteMap>
  </system.web>
  <connectionStrings>
    <add name="classifiedsConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\CLASSIFIEDSDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
<add name="membershipConnection" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>      
</configuration>

and i have aspnetdb.mdf and classifieds.mdf files in may app_data folder, but it still doesnt work. the full text of the error im getting is:

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)"

هل كانت مفيدة؟

المحلول

Within your membership provider information you need to change the connectionStringName to "classifiedsConnection". Also make sure that your CLASSIFIEDSDB.mdf file is actually residing in the App_Data folder on the host.

<membership defaultProvider="AspNetSqlMembershipProvider">
   <providers>
      <clear/>
      <add name="AspNetSqlMembershipProvider"
           type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
           connectionStringName="classifiedsConnection"
           enablePasswordRetrieval="false"
           enablePasswordReset="true"
           requiresQuestionAndAnswer="true"
           applicationName="/"
           requiresUniqueEmail="true"
           passwordFormat="Hashed"
           maxInvalidPasswordAttempts="5"
           minRequiredPasswordLength="7"
           minRequiredNonalphanumericCharacters="1"
           passwordAttemptWindow="10"
           passwordStrengthRegularExpression=""/>
    </providers>
</membership>

نصائح أخرى

@BrianR's advice is good (the membership configuration pointed to a non-existant connection string).

However, in addition to that this question is really too specific to your hosting provider to be relevant here on stack overflow. You should contact your hosting provider directly via technical support.

The error you are seeing means IIS/ASP.net can't find SqlServer. This is going to be a result of misconfiguration of either your connection string or the hosts web server. That is why this question is specific to your host and not applicable to other users who may find this question via google. It will be different for different hosts.

  • Some hosts will have full SqlServer installed, some will just have SqlExpress. The full version of SqlServer does not install with the same default instance name and may have other configuration differences.
  • Some hosts may change the instance name from defaults like 'SQLEXPRESS' for security reasons or other system management reasons. (Even if SqlExpress is installed, it does not necessarily mean it is accessible via './SQLEXPRESS')
  • Some hosts use independent database servers (not on the same windows server instance as your website) and you may need to include a machine path, IP address, port number, security credentials or other details to access it. Your host would provide this information to you if that is the case. Sometimes it is documented, some smaller hosts might require that you submit a support ticket (if in doubt, go for the support ticket!).

Because of these potential configuration differences from one host to the next, you really need to contact them. You likely have included technical support for this purpose!

Edit #1

Your subsequent edit of the question did not change the above information. You are still experiencing an error that suggests you cannot connect to SqlServer. You still need to verify with your hosting provider that SqlExpress is installed, that you have the correct credentials/permissions to access SqlServer and that your two database files do in fact exist in the correct location with the correct permissions.

Even if you had an incorrect database schema, you would not get this particular error. So it has to be related to the configuration of SqlServer/SqlExpress, your data files and your web/config. These settings are specific to your host and not something that can be answered generally on stackoverflow.

Your hosting provider might not have SQLExpress installed. (SQLExpress is not part of the dot.net framework, it is a different product.)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top