Lightswitch Web Deploy - Error 26 - sql-server

I have a very simple Lightswitch application (HTMLClient and DesktopClient) developed on my local machine in VS 2013. I can run this locally with no issues.
I also have a remote server with IIS8 (APP02) and separate SQL server (SQL01) running SQL 2012 Standard 64 bit, both on the same domain. I can connect to the SQL server without any issues from the IIS server using a test .udl file. The IIS Server also has a sharepoint installation and all of the associated databases for this are on the SQL server.
When i Publish the Lightswitch App directly to the IIS server, after carefully following Beth Massi's article here: http://blogs.msdn.com/b/bethmassi/archive/2011/08/16/10145037.aspx?PageIndex=4#comments, I get the following error:
Error 98 An exception occurred when deploying the database for the application.
An error occurred while establishing a connection to SQL Server instance 'SQL01\SQL2012DEV'.
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)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\LightSwitch\v4.5\Publish\v2.2\Microsoft.LightSwitch.Publish.targets
1565 10
IIS8LightswitchApp
The IIS application is created successfully and i can navigate to it using the public URL, but no database is created at all. There is nothing in the Event Log of the SQL server related to this either.
When i publish the app to a package and install the .zip file in IIS manually, the app is deployed to IIS and SQL with no issues.
I've scoured this site, Lightswitch forums, and the web in general looking for a resolution but so far nothing has worked. A few things that i have tried are:
Changed the Log On user in Web Deployment Agent Service to a domain admin account
Changed the Log On user in Web Management Service to a domain admin account
Checked the firewalls on both servers (tried turning them off)
Does anyone have any suggestions I can try please? Also posted on the Lightswitch forums.

Have you tried configuring the IIS Server to host LightSwitch Apps using Web Platform Installer - http://msdn.microsoft.com/en-us/library/gg481779.aspx

Related

ASP.NET MVC app connects to Azure SQL Server db using server explorer, but gets "A network-related or instance-specific error" when locally hosted

I have two ASP.NET MVC applications that connect to the same Azure SQL Server database. I've used both for a long time.
I recently reinstalled my local machine and got the files for both applications from TFS. One of them works with the database just fine. The other one can connect to the database using Visual Studio's Server Explorer using the EF connection string, but when I try to run it locally I get error 26:
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)
I have checked my local IP is allowed through the Azure firewall. Any ideas why the second application won't run locally? A port issue or a cached file?
Thanks
My app is a small test application and I only used it locally so I never implemented the Owin Identity that was included in the generated project.
I had updated Visual Studio when I updated to Windows 10. Perhaps that made the Owin Identity mandatory. When I added a connection string for the identity system the app worked without issue again.
So it was an issue with the connection string, just not the EF connection string.

ASP.NET Core Web Api publishing to IIS producing an Sql Server connection error

I've created a simple web api in asp.net core 2.0 which uses localdb as the backing datastore. It works completely as expected in debug - I'm able to send requests from postman (or browser) and step through my code. Here is my connection string:
"Server=(localdb)\\MSSQLLocalDB;Database=UniversityDatabase;Trusted_Connection=True;MultipleActiveResultSets=true"
I now want this to be running constantly so that I can consume it from a Xamarin.Forms project so I have tried publishing the web app using the Visual studio wizard.
1.
2.
UniversityApi then appears in IIS under Default Web Site but not as an application. I choose to 'Convert to Application' which shows me this dialog:
3.
The NetCoreApps Application Pool uses No Managed Code.
Error:
{
"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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.\r\n)"
]}
The error seems to describe a problem with connecting to my Sql Server instance which is strange because it works perfectly while debugging in VS. Any ideas?
After searching for a while I stumbled onto this question:
SQL won't connect after deploying
One of the answers did the trick for me, credit to Robotron.
IIS Manager
Application Pools
Find the pool your app belongs to (for me it was .NET v4.5)
Right click -> Advanced Settings
Scroll down to Identity
Change from whatever (for me it was ApplicationPoolIdentity, same as you have) into LocalSystem.
Add the "LOCAL SERVICE"(Windows account) to SQL Server.
Change from "ApplicationPoolIdentity" to "LocalService" in (IIS Application Pools Advanced Settings)
NOTE. ADD "LOCAL SERVICE"(Windows account) need Permission into SQL Server.
Thanks a lot for the answers. I have similar problem. My .net core web api is hosted in AWS. It was working before when I was just accessing the api via ip address (sample https://xx.xx.xxxx/swagger) but when I integrated it to domain (https://xx.sampledomain.com/swagger) I ran into the same problem. These two steps solved the error.
1st I used the LocalService account for IIS Application Pool, then added the NT Authority/Local Service account in the MS SQL Server 2016.
enter image description here
On the Publish screen > Database > DefaultConnection, I ticked on the 'Use this connection string at runtime' checkbox.
enter image description here

Dotnet core application cannot connect to SQL server using IIS, only when using IIS Express or Kestrel

I have a .NET Core web application that fetches some data from a SQL Server. I connect to the SQL Server over the internet.
When I run the application with IIS Express or Kestrel, I can connect to the database server and retrieve data. I can also successfully connect to the database server using SQL Server Management Studio.
Here is the connection string I'm using:
"ConnectionStrings": {
"DefaultConnection": "Server=my-sql-server.someurl.com; Initial Catalog=my-sql-database; User ID=my-user-id; Password=my-password;"
}
But when I try to run the same website, on the same machine, in IIS, I get the following error message:
SqlException: 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: TCP Provider, error: 0 - No such host is known.)
I'm suspecting this has something to do with the dotnet core/IIS combination, and not a firewall/network/authentication issue, but I might be wrong.
The issue was simply that I was looking at the wrong connection string.
I have appsettings.json containing one connection string and appsettings.Production.json containing another.
When running the application with IIS Express or Kestrel, the first one is used, but when I publish the app and then run it under IIS, the environment is set to Production, and the production settings are used instead.
The problem was that the production connection string pointed to a database server that didn't exist anymore.
I solved this issue by adding LocalSystem to Identity in Web site Application pool.
Steps:
Select website application Pool
Right click and click Advanced Setting
Click on Identity, and change it to LocalSystem
You need to enable TCP/IP protocol on sql server. Please use following link:
Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"?

"The server was not found or was not accessible" from IIS

I have a major problem connecting to mssql server from IIS hosted application. Still same 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.
I have access to this database via Managment Studio. I also tested my connection string in a desktop testing app on the same machine and is working fine. Also, i had hosted older version of this app on another server (with an older version of IIS) and also worked fine.
I don't have direct access to database or firewall etc. Also, I cannot debug app in Visual Studio.
Any ideas?

Connecting database to MVC application - Error 50 Local database runtime error occurred

I am having a hard time in connecting my database to my MVC Application. I keep getting the following error, despite the recommendations that I have found online.
System.Data.SqlClient.SqlException: 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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
Background situation:
I have developed an MVC Web App with User database, and I would like to publish them on another computer. After copying the files to the host computer, however, I was unable to access the SQL Server, with the following error message: Error 50 Local Database runtime error occurred.
The followings are the steps I have taken from the start of publishing process to the end:
I have created an MVC Web Application on my personal computer, with a user login authentication as described in Rick Anderson's example: http://www.asp.net/mvc/overview/security/aspnet-mvc-5-app-with-sms-and-email-two-factor-authentication. Therefore, with the Web App, I have a default user database created with it.
I then deployed the App to my own C:/inetpub, by using Visual Studio 2013. The publishing method is "File System". I understand that Database publishing is not supported for this publish method. So after the Web App was published, I created a folder named "App_Data" in my C:/inetpub/wwwroot, and copied my mdf and log database from my Project folder in VS2013 into it.
Afterwards, I opened up IIS7 on my computer and set my Default Website's physical property to C:/inetpub/wwwroot. I opened my web browser and I could connect to both the website and my databse (meaning I can login through the website, and it manages to authenticate my login id). So it was all good when the web app was running on my computer.
Next, I had to install the Web App to the host computer where it will be hosted.
So I copied the whole MVC Folder (C:/inetpub/wwwroot) and put it in the host computer's C:/inetpub/wwwroot. Then I did the following settings:
In the host computer, I gave IIS_IUSRS read/write access to the database.
I opened MSSQL 2014 SSMS, connected to Server: (LocalDb)\MSSQLLocalDB, and added a new database, i.e. the database.mdf in my C:/inetpub/wwwroot/App_Data. So my user database is registered in SSMS.
The connection string in my IIS was then changed to (LocalDb)\MSSQLLocalDB because I have MSSQL 2014 installed on the host computer.
<add connectionString="Server=(LocalDb)\MSSQLLocalDB;Database=aspnet-MvcPWy-20140708072924;Integrated Security=true" name="DefaultConnection" providerName="System.Data.SqlClient" />
ApplicationPool settings for IIS7 was following this example
<add name="DefaultAppPool">
<processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="true" />
</add>
Despite all those configurations, however, I am still getting the same error. I would greatly appreciate if anyone could review my steps and see if I have made a mistake or missed some steps in setting this database. Thank you!

Resources