.NET 6 sql connection issue.

Gev Gev 1 Reputation point
2022-12-12T18:25:07.62+00:00

Hi Friends.

I am facing an issue when trying to open connection in ASP.NET MVC (.NET 6). the SQL server is 2019.

I tried to connect with .NET Framework and it is connecting successfully. but with .NET 6 I am getting the connection issue.

I am using this namespace for DB connection System.Data.SqlClient.

here is the code example with Console application

using System.Data.SqlClient;

var connectionStr = "data source=*...;uid=userid;password=mypassword;database=MyDB;Connect Timeout=1000; Encrypt=False";
try
{

using var connection = new SqlConnection(connectionStr);  
{  
    connection.Open();  
    var state = connection.State;  
    Console.ForegroundColor = ConsoleColor.DarkGreen;  
    Console.WriteLine("END");  
}  

}
catch (Exception ex)
{

throw;  

}

here is the error message:

"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)"

Thank you so much for your attention my Friends.

Developer technologies .NET Other
SQL Server Other
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.