简体   繁体   中英

ASP.NET losing connection to SQL Server Express after being published to IIS

I have an ASP.NET application that gets data from a SQL Server Express on the same computer. When I run the ASP.NET project from Visual Studio, the project can reach the database just fine. However, when published to IIS, the project loses the connection. Here is my connection string located in Web.config :

<connectionStrings>
    <add name="conString" 
         providerName="System.Data.SqlClient" 
         connectionString="Server = DESKTOP-EVAN\SERVER;Database=master;User ID=sa;Password=12345;" />
</connectionStrings>

The project can be reached on the published IIS, however no data is there and no error messages show.

I've added the application pool and NT Authority to the SQL login but still no luck connection to the database.

Does anyone have any experience with this? How can I get my published ASP.NET project to connect to my SQL Server Express?

您是否尝试过删除服务器的空间,如下所示:

 Server=DESKTOP-EVAN\SERVER

Did you install SQL Server Express on that machine where IIS is running, or on a machine that can be reached from the IIS machine?

Also : did you explicitly define a separate instance name for your SQL Server Express when installing?

By default, the instance name would be SQLEXPRESS - but you seem to refer to DESKTOP-EVAN\\SERVER - so SERVER would be your instance name - is that the case??

If not : can you try DESKTOP-EVAN\\SQLEXPRESS as the server/instance name instead?

<connectionStrings>
    <add name="conString" 
         connectionString="Server=DESKTOP-EVAN\SQLEXPRESS;Database=master;User ID=sa;Password=12345;" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

You muss allow user for iis in security. Here is oné video: https://youtu.be/rmVtxLKmkDU

I hope thats help you.

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