Unable to publish ASP.NET database to external server - c#

I'm trying to publish my ASP.NET MVC application to my server running Windows Server 2008.
I have installed IIS
I have created a database in on the (LocalDb)\v11.0 server on the destination server (The DB is named TestPublishWebApp).
I've clicked publish and have set the connection (and validated the connection):
And I have set the settings as well:
However whenever I publish the application I and go to the URL I get the following 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.
This is the very first time I'm trying to publish an application to an external server. What could I be doing wrong?
And yes, I have verified that the SQL server is running.

Related

ASP.NET Core Web 3.1 - IIS Express can fetch data from localdb but local IIS can not

I have a very weird problem as stated above.
The code running is exactly the same, the only difference is the Debug profile used. I'm using Microsoft Visual Studio Community 2019 Version 16.6.3.
When using the IIS profile the code says I have no Media in my database.
Switching profile to IIS Express, now I have Media using the exakt same connection string as can be seen in Immediate Windows.
I first suspected that the ASP.NET Core Web 3.1 had a problem fetching the connection string from appsettings.json and that it was needed in web.config as well. Tried adding it but it did not make a difference. Checking context.Database.GetDbConnection().ConnectionString also shows the same for both profiles so this is not the case.
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=(localdb)\\mssqllocaldb;Database=<MYDB>;Trusted_Connection=True;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" />
</connectionStrings>
If I look at the database via SSMS I can see my Media as expected.
The IIS Application Pool runs as LocalSystem. If I switch to a user that does not have access to the database like ApplicationPoolIdentity I get an exception as expected in Windows Event Viewer and the application does not start correctly.
Microsoft.Data.SqlClient.SqlException (0x80131904): 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.
Using LocalSystem everything looks fine in Event Viewer but it says I have no Media or any other data.
How can two identical connection strings using the same code show different results?
Tried switching Application Pool Identity to my currently logged in user that I know has access via SSMS:
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.
Error occurred during LocalDB instance startup: SQL Server process
failed to start. )
With this and the comment from #nilsK I fixed it like this:
Start by using Developer PowerShell or Developer Command Prompt for Visual Studio as Administrator and confirm that you only have one instance of LocalDb.
Type sqllocaldb info to see your LocalDb instances.
I then followed this article and had Application Pool Identity still set to my currently logged in user, credit: https://stackoverflow.com/a/38294458/3850405
https://learn.microsoft.com/en-us/archive/blogs/sqlexpress/using-localdb-with-full-iis-part-1-user-profile
In there I found that it is not enough to have Load User Profile set to true for your Application Pool, you also need to set setProfileEnvironment to true in applicationHost.config normally located at C:\Windows\System32\inetsrv\config. With this configuration it worked:

Deploy ASP.NET MVC app on Azure portal with SQL database

How I can move my local database in project in order that I can deploy this database to Azure? Know on Azure when I login I get an error:
Error: an error occurred while processing your request
It is because I have no connection to my database. I have created the database on Azure portal but it's empty. How can I connect to my database from my app so that it works?
This is the complete error:
[Win32Exception (0x80004005): The system cannot find the file specified]
[SqlException (0x80131904): 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: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)]
....
[EntityException: The underlying provider failed on Open.]
The solution:
When you deploy app click 'Publish' - > 'Create new Profile' -> In field 'Explore additional Azure Services' click - > 'Create a SQL Database'
According your comment, you problem turned to be deploy database to Azure.
There are many ways you can to that.
Since you have created the database on Azure portal, the easiest way is that you can using SSMS Deploy Database wizard:
For more details, you could reference this tutorial: Learn how to Migrate a SQL Server database to SQL Azure server.
Once the database is deployment to Azure SQL database successfully, you could get the connection string on Azure SQL database page on Portal:
Ref:Get ADO.NET connection information (optional)
hope this helps.

Publish application and include .dbo and tables?

I am trying to publish my Windows forms application which uses a data connection (.dbo) for tables that run my application. However, when I publish the application, I get errors saying the application cannot access the SQL database.
I have looked through YouTube videos and read on the Windows website but I cannot really find anything that solves my problem. The server is a local server named after my laptop name. All of them talk about .mdf databases but I can only see a .dbo under data connections which includes all the tables I created for my application.
I get the following error:
"Unhandled exception has occurred in your application...
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 the instance name is correct and that SQL Server is configured to allow remote connection. (provider: Named Pipes Provider. error: 40 - Could not open a connection to SQL Server)"
It works fine when I run the .exe file on my computer where I built the application but the above error is given when I run the application on another computer.
Can anybody help me publish my application to include the .dbo and all tables?

SQL Server Reporting Services LocalDB doesn't exist error

I've been trying to view deployed reports in SSRS using Visual Studio 2015 and SQL Server 2014, but this is the error message I've been receiving:
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. The specified LocalDB instance does not exist. )
This is what my connection string looks like:
Data Source=(localdb)\VIRAJ-PC;Initial Catalog=AdventureWorks2012
I've done numerous things to troubleshoot this problem including editing the firewall settings to open ports 1433 and 1434 that need to be accessed, made sure that the MSSQLSERVER service was running, configured the local server to allow incoming connections, have turned on TCP/IP and Named Pipes protocols through the configuration manager, and have checked to see if the LocalDB instance is running through sqllocaldb.exe in the command line (it is running).
If it matters at all, I'm using SQL Server Management Studio 2016. I don't want to have to do an uninstall as I've done so two or three times already because of previous errors and have gone through a lot of configuration so if there's a way to fix this without having to just reinstall, I would appreciate it.

Network related error while deploying a window application & used database to another pc

My window application works fine on my computer but when I install it on another computer a network-related error occurred...
I'm using sql server 2005, I have store the backup of the database, when i run it, it flags an error.
I'm using visual studio 10, C#,sql sever 2005
Error is..
"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)""
When this happens it means that the program cannot connect to SQL Server with information you provided.
If for example you are trying to connect my-server\sqlexpress, usually you have one of this issues:
There is no computer named my-server in your network!
SQL Server is not installed on my-server.
Your client computer cannot reach my-server from the network. You can check this using ping command.
The installed SQL Server instance name on my-server is not sqlexpress (case-insensitive).
You have not enabled TCP/IP protocol for your installation instance of SQL Server in "Sql Server Configuration Manager".
You have not restarted SQL Server service after enabling TCP/IP.
Your SQL Server instance is not default instance, and SQL Server Browser service is not running on the server.
Server's firewall is preventing the client to access the server. Try turning off the firewall on the server (only to test this case).
Consider this a checklist, and start from the beginning. Check them one by one. And I hope that you find the problem.

Categories