3

could anyone help me with this ? Everything works fine in Visual Studio, but does not on a remote server. I have tried to access the page while logged in and logged out, but has got the same error. Error : "System.Data.SqlClient.SqlException: Login failed for user 'ASPHOST166\IWAM_plesk(default)'."

Web.confing:

 <?xml version="1.0" encoding="utf-8"?>
 <!--
    For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
 -->
 <configuration>
 <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****" providerName="System.Data.SqlClient"/> 
    <add name="ApplicationServices" connectionString="Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****" providerName="System.Data.SqlClient" />
    <add name="DatabaseEntities" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
<system.web>
 <compilation debug="false" targetFramework="4.0">
   <assemblies>
     <add assembly="System.Security, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
     <add assembly="System.Data.Entity.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
    </assemblies>

  <buildProviders>
    <add extension=".edmx" type="System.Data.Entity.Design.AspNet.EntityDesignerBuildProvider" />
  </buildProviders>
</compilation>
  <customErrors mode="Off"></customErrors>
  <trace mostRecent="true" enabled="true" requestLimit="1000" pageOutput="false" localOnly="true"/>
 <authentication mode="Forms" />
 <membership>
   <providers>
     <clear />
     <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
   </providers>
 </membership>
 <profile>
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
   </providers>
 </profile>
 <roleManager enabled="true">
   <providers>
     <clear />
     <add connectionStringName="ApplicationServices" applicationName="/"
      name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" />
    <add applicationName="/" name="AspNetWindowsTokenRoleProvider"
      type="System.Web.Security.WindowsTokenRoleProvider" />
   </providers>
 </roleManager>
</system.web>
<system.webServer>
 <modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
 <location path="Moderation">
     <system.web>
        <authorization>
            <allow roles="Admin" />
                <deny users="*" />
            </authorization>

        </system.web>

    </location>
 </configuration>

Code behind the page (inserting) :

 protected void EntityDataSource1_Inserting1(object sender, EntityDataSourceChangingEventArgs e)
 {
     Good pic = (Good)e.Entity;
     //pic.PhotoAlbumId = photoalbumid;
     FileUpload fileupload1 = (FileUpload)ListView1.InsertItem.FindControl("FileUpload1");
     string virtualFolder = "~/pics/";
     string fizfolder = Server.MapPath(virtualFolder);
     string filename = Guid.NewGuid().ToString();
     string extension = System.IO.Path.GetExtension(fileupload1.FileName);

     fileupload1.SaveAs(System.IO.Path.Combine(fizfolder, filename + extension));
     pic.ImageURL = virtualFolder + filename + extension;
     pic.Date = System.DateTime.Today;

 }
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
Rennos
  • 93
  • 1
  • 3
  • 11

4 Answers4

6

Looks like your application runs under account which is not exist in SQL server. Thus you have login and password specified in connection string for Entity Framework, I think you need remove Integrated Security=True; from this Entity Framework connections string:

<add name="DatabaseEntities" 
     connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=ASPHOST166\SQL2008R2,778; Initial Catalog=Rennoz_DATABASEMDF; User ID=Rennoz_Admin; Password=*****;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;" 
     providerName="System.Data.EntityClient" />

UPDATE: According to your error message, user instance login flag is not supported on your version of SQL server. So remove also User Instance=True; parameter.

Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459
3

Your DatabaseEntities connection string specifies User ID and Password but also Integrated Security=true (which takes precedence). Remove the latter to use the specified SQL account.

Also remove User Instance=true - it is only used when attaching MDF files dynamically.

Knaģis
  • 20,827
  • 7
  • 66
  • 80
0

I had a similar issue.

I let Plesk handle my connection string and then removed it from my web.config file but that's up to you.

1) I created the user "CT11881\IWAM_plesk(default)" under logins, using Windows Authentication.

2) Granted the user full access in "Server Rolls" and "Securables"

http://forums.asp.net/t/1954164.aspx?Windows+2008+VPS+w+Plesk+11+x+SQL+connection+issues

Cody Hicks
  • 420
  • 9
  • 24
0

To have to use IntegratedSecurity if your SQL server is located on different machine, you should run your site under the same credential which are allowed in SQL server.

  1. If your Web machine not in domain, you should create the same user with the same credential on both machines (Web and SQL). In the "SQL Server Management Studio", add this user and set needed priviledges.
  2. In the IIS, go to your application pool, click "Advanced settings" and set credentials (for user which you created or for domain user) in the property "Identity".
  3. In the IIS, in your site, go to "Advanced settings" and set credentials (for user which you created or for domain user) in the property "Physical Path Credentials".
  4. In the "ConnectionString", if you are used "localhost" in the property "source", change it on UNC address, where is located your SQL server.
  5. If connection can't be established, make sure that the TCP/IP protocol is enabled in the "SQL Server Configuration Manager" for used SQL instance (after change, need to restart an instance) and that is TCP port 1443 is alowed in firewall on your SQL machine. You can ping this port from the Web machine with help "Paping" utility - "paping YourSqlMachine -p 1433 -c 4".
Pavel K.
  • 983
  • 9
  • 21