Razor core app connects to DB, but integration test fails with Microsoft.Data.SqlClient.SqlException

Walter 1 Reputation point
2024-09-28T14:36:46.4833333+00:00

I have an app that I've been writing and its working well. When I introduced an integration test, its unable to connect to the DB using the exact same connection string.

Microsoft.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: SNI_PN11, error: 50 - Local Database Runtime error occurred. Specified LocalDB instance name is invalid.)'

The integration test has the same nuget packages plus some test packages. Its not a network error because its all on my local development machine. I also tried another machine and get the same error, so its not that something that needs to be reinstalled.

Microsoft Visual Studio Community 2022 (64-bit) - Current - Version 17.11.2

Microsoft SQL Server 2019 LocalDB - 15.0.4153.1

I have no idea what else to look for to resolve this. Please help

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,137 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,841 questions
{count} votes

1 answer

Sort by: Most helpful
  1. LucyChenMSFT-4874 4,750 Reputation points
    2024-09-29T08:27:12.1733333+00:00

    Hi @Walter,

    Thank you for your reaching out and welcome to Microsoft Q&A!

    There could be several reasons for this error, and it would be helpful to gather more information to help troubleshoot the issue.

    Please refer to A network-related or instance-specific error occurred while establishing a connection and follow the steps in it to SQL Server to take a check!

    I hope this helps! If you have any more issues or need further assistance, feel free to share with us!

    Best regards,

    Lucy Chen


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    https://docs.microsoft.com/en-us/answers/support/email-notifications


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.