Random error: System.Data.EntityException: The underlying provider failed on Open - c#

I have been getting this error in my C# app:
System.Data.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: Shared Memory Provider, error: 0 - No process is on the other end of the pipe.) ---> System.ComponentModel.Win32Exception: No process is on the other end of the pipe
The strange part though, is that it only occurs sometimes. I can never seem to reproduce it, and its very random. The userid/password in the connection string is correct, and I haven't messed with any of the SQL server configuration settings. I'm using Entity Framework 6.1.0.

Related

EF Core .NET server connects but pre-login handshake error

The error:
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 35 - An internal exception was caught)
This is my connection string:
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=BulbPayrollManagement; Trusted_connection=True;"
}
I am trying to update database in my Mac. The database server - SQL Server is running in a Docker container. I keep getting the above error whenever I run the database update command.
How do I fix this ?

(0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. on macOS and dockerized SQL Server

I'm building a dotnet app using Rider and Docker under macOS. For the database, I use sqledge docker image. If I start the service and send a request, I receive a successful response. When I containerize the dotnet app, I receive the following error:
An error occurred using the connection to database 'FundraiserAPI' on server 'localhost'.
fail: Microsoft.EntityFrameworkCore.Query[10100]
An exception occurred while iterating over the results of a query for context type 'Raiserflow.CampaignOrgAPI.DbContext.FundraiserDbContext'.
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: TCP Provider, error: 40 - Could not open a connection to SQL Server: Could not open a connection to SQL Server)
It's a common error that says that my dockerized service doesn't have access to the SQL container.
One of the ways to fix the error is to Enable TCP/IP port
As macOS doesn't support SQL Server Configuration Manager, do you know any other alternatives to enable the TCP/IP port of a SQL server in a docker container?
Attaching a screenshot of my 2 containers and the ports they're running.
And my connection string:
"DefaultConnection": "Server=localhost;Database=FundraiserAPI;Initial Catalog=FundraiserAPI;User=sa;Password=123123;MultipleActiveResultSets=True;"
Or if you have any other alternative solution, that would be great!

Error when accessing LocalDB from UWP: Unexpected error occurred inside a LocalDB instance API method call

I have an UWP application with an EFCore 2.1 datalayer which has to get data from a LocalDB, but I'm getting the following error:
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. Unexpected error occurred inside a LocalDB instance API method call. See the Windows Application
event log for error details.
In the Windows Application event log, I have the following errors:
Windows API call CreateMutexW returned error code: 5. Windows system
error message is: Access is denied.
Unexpected error occurred while
trying to access the LocalDB instance registry configuration. See the
Windows Application event log for error details.
Windows API call
FormatMessageW returned error code: 1815. Windows system error message
is: The specified resource language ID cannot be found in the image
file.
Notes:
I can connect to the LocalDB with SSMS.
I have an API in .Net Core 3.1 which is using the exact same datalayer and connection string on the exact same LocalDB, but there's no error on this project and the data are correctly retrieved.
The UWP application can connect correctly to a SQL Server or SQL Express DB with also the same datalayer: only the connection string is changed.

Update-Database command giving error in establishing connection to the server (Code First Migration)

I created this project on my another system and completed. I used code first migration for creating database. On that system, this app was running correctly.
But now when I had transferred the project to another system, Its package manager is showing 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: 26 - Error Locating Server/Instance
Specified)
I tried with Update-Database -Vebrose, I observed that it is targeting wrong data source, which was in that system where I created the project. How to solve this issue?
Check if the app.config has the connection string set. It may have the connection of the "old" machine that is now unaccessible.
Is the SQL Server configured to allow remote connections?
Is the port 1433 (the SQL Server default port) open?
If you only have the text you sent in the web.config, the connection string might be elsewhere.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. Error handling with exe

Getting 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 1326)
I have an exe file of a software. When I open this .exe file and login with correct email or password. But system throws this error. I have been searching out in stack overflow they do not explain this error handling with exe.
Is it i will convert from exe to source cod ?
I am new I don't know better.The client ask me that you removed this error. This system developed by another developer.
I don't know what should I do ?
Thanks in advance. Who give me answer he will be appreciated by me.

Categories