sql-serverasp.net-mvcentity-framework

How to fix the "system cannot find the file specified" error in ASP.NET MVC and SQL Server 2019


I wrote a code-first application, but when running the app, I get this error and it doesn't create the database - I'm using SQL Server 2019.

Please help me - I can't run my app.

Server Error in '/' Application.

The system cannot find the file specified

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception details: System.ComponentModel.Win32Exception: The system cannot find the file specified

Source Error:

Line 71: // This doesn't count login failures towards lockout only two factor authentication
Line 72: // To enable password failures to trigger lockout, change to shouldLockout: true
Line 73: var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
Line 74: switch (result)
Line 75: {

Source File: G:\MvcProject\OPA finally\OPA finally\Controllers\AccountController.cs Line: 73

Stack Trace:

[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.)]

System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4075.0

My connection string is true but it's not working.

web.config connection string:

<connectionStrings>
    <add name="DefaultConnection" 
         connectionString="Data Source=.;Initial Catalog=DefaultConnection;Integrated Security=True;" 
         providerName="System.Data.SqlClient" />
</connectionStrings>

Thank you for answer


Solution

  • First check SQL Server Agent is running. enter image description here

    Most of the times it means that the connection string is incomplete. If you're not using Windows authentication, you need to provide uid=YourUserName; Password=yourpassword;. Check the logins in sql server db (Navigate to Security > Logins).

    Otherwise try specifying Server name inside the connection string. If you have a named instance then you should set it like this i.e Server=localhost\sql2019

    And also InitialCatalog is the name of the db. Is it "DefaultConnection"?

    Also take a look at the properties in your db. enter image description here