简体   繁体   中英

Can't connect from IIS to localDB

I'm trying to develop a WebService between me and my roomate (so a local one).

I created a Database (.mdf) saved in one of my folders and some aspx pages that access to it and retrieve informations. Now I was trying to deploy the project under IIS and I'm getting a problem when I have to access to the local db.

provider: SQL Network Interfaces, error: 50 Server not found or not accessible.

Everything from Web Visual Studio works fine! So if I try to connect the DB just running from VS on Google Chrome everything is fine. This error appears only when I try to run it under IIS 8.0

(my string connection = Server=(LocalDB)\\v11.0;     

AttachDbFilename=C:\\Users\\Asus\\Desktop\\RobaMia\\SQLSERVER\\WindowsFormsApplication3\\WindowsFormsApplication3\\Database2.mdf;
Integrated Security=True;Connect Timeout=30;User Instance=False)

Could it be that "User Instance = False" makes the trick?


I say also that all my application pools are user-set http://i.imgur.com/jrOZxTO.jpg

Probably your IIS Application Pool doesn't have permission to open your database file C:\\Users\\Asus\\Desktop\\RobaMia\\SQLSERVER\\WindowsFormsApplication3\\WindowsFormsApplication3\\Database2.mdf. I would suggest to change the application pool identity to your local windows user.

See this link: Using LocalDB with Full IIS, Part 1: User Profile - SQL Server Express WebLog - Site Home - MSDN Blogs

I too had the same problem.

  1. From the visual studio disconncect the data connection from the server explorer to the reference database.(It allows to copy the file)
  2. Publish your project as you do , personally I do file system.
  3. Copy App_Data manually form the your local project to the published path.
  4. In IIS double click the Application Pools.
  5. Click on "Set Application Pool Default" in right top corner of the explorer.
  6. Under Process Model go to identity and select "Local System"
  7. Done Good luck.

It works for all the web api that you are testing in iis. It worked for my xamrine.android app testing only when hosted in IIS and not in Express.

I had this in my web.config. Removing it fixed the issue for me

<identity impersonate="true" / >

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