简体   繁体   中英

Unable to connect database using ADO.NET entity data model when website is hosted in IIS

I am using an ADO.NET Entity Data Model ( .edmx ) approach in my website. It's working fine in local system but when I hosted this application in IIS, I am not able to connect to the database. There's a problem with my server connection string. Please let me know how to resolve this issue and how to make sure my server connection string is valid.

This is my local system connection string:

<add name="myconnectionstring" 
     connectionString="metadata=res://*/App_Code.db.csdl|res://*/App_Code.db.ssdl|res://*/App_Code.db.msl;
     provider=System.Data.SqlClient;
     provider connection string=&quot;Data Source=myservername;
         Initial Catalog=databasename;Integrated Security=True; 
         MultipleActiveResultSets=True;App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

This is my server connection string:

<add name="myconnectionstring" 
     connectionString="metadata=res://*/App_Code.db.csdl|res://*/App_Code.db.ssdl|res://*/App_Code.db.msl;
        provider=System.Data.SqlClient;
        provider connection string=&quot;Data Source=myservername\SQLEXPRESS;
             Initial Catalog=databasename;Integrated Security=True; 
             MultipleActiveResultSets=True;App=EntityFramework&quot;" 
        providerName="System.Data.EntityClient" />

When you are execution your program on your local computer, you use your User to connect to your database. When you publish on your Webserver with IIS (I'm assuming you are using IIS 7.0), the default user will be "IUSR". With this information, you need to verify if the IIS user as access to the database in the security setting of the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM