locked
Server Error in '/MVCDemo' Application. The system cannot find the file specified RRS feed

  • Question

  • User-1128363788 posted

    I have an error regarding connecting to my database while querying "employee" from browser using this query string:

    http://localhost/MVCDemo/employee/details/1

    Screenshots from my desktop for the error:

    https://ibb.co/tPGwSGW
    https://ibb.co/DbKZgVQ

    Screenshots from Visual Studio:

    https://ibb.co/rMWp8wX
    https://ibb.co/GRPM1Yz

    And from SQL Server Management Studio:

    https://ibb.co/HKW7gZ6

    I googled a lot and the reason is often related to the connection string or a network error in my Windows 10. I tried using other connection strings while paging Stackoverflow.com

    but that didn't solve the problem.

    Your help is appreciated.

    Saturday, May 11, 2019 3:58 PM

All replies

  • User839733648 posted

    Hi mahmoud_arafa,

    According to your description and screenshots, I suggest that you could check the following steps.

    • Check if your connectstring is right.
    1. Open the SQL Sever Object Explorer.
    2. Find the Database you want to connect to and right click on it to find the Properties item.

    Find the Connection string item in General settings and copy the string to Web.config.

      <connectionStrings>
        <add name="ConnectionStringName" connectionString="Paste the Connection string" providerName="System.Data.SqlClient"/>
      </connectionStrings>
    • Check the settings in Sql Server Configuration Management
    1. Open the Sql Server Configuration Management ( How to open )->SQL Server Network Configuration->Protocols for 'servername' and check TCP/IP is enabled
    2. Open SSMS in run, and check you are able to login to server using specfied username/password and/or using windows authentication.
    3. Repeat step 1 for SQL native client config also.

    Best Regards,

    Jenifer

    Monday, May 13, 2019 2:45 AM
  • User-1128363788 posted

    @Jennifer

    "Find the Connection string item in General settings" ..

    I cannot find the connection string in the properties item:

    https://ibb.co/5FK82zw.

    Monday, May 13, 2019 4:35 PM
  • User753101303 posted

    Hi,

    What if you try server=(local) or server=localhost instead ?

    Monday, May 13, 2019 4:56 PM
  • User-1128363788 posted

    Jenifer Jiang

    Check the settings in Sql Server Configuration Management

    Done.

    Jenifer Jiang

    Check if your connectstring is right.

    I can't find the connection string in General settings in Properties item.

    The same error exists still after rebuilding from Visual Studio.

    Tuesday, May 14, 2019 3:08 AM
  • User839733648 posted

    Hi mahmoud_arafa,

    I suggest that you could check that if your database is in local server because you use "." which means local.

    I've seen that the database you've connected is master. 

    Usually, there is a database named master there which we could not use it.

    Please recheck that which database you want to connect.

    mahmoud_arafa

    I cannot find the connection string in the properties item:

    You should try to find the connectstring in the SQL Sever Object Explorer in your Visual Studio not in SSMS.

    Best Regards,

    Jenifer

    Tuesday, May 14, 2019 5:52 AM
  • User-1128363788 posted

    @Jennifer

    I created a new database called "Sample" that is different from system databases and inside it I created a table called "tblEmployee".

    I opened SQL Sever Object Explorer and I didn't find the "Sample" database I have created ..

    https://ibb.co/MfG0Sck

    Tuesday, May 14, 2019 2:41 PM
  • User753101303 posted

    Hi,

    Seems there is some confusion about which db server is used ?

    What if you create a new EmployeeContext and use yourContext.Database.Connection.ConnnectionString to make 100% sure about which connection string is used ? Does it really match the one you shown ?

    Edit: try maybe https://docs.microsoft.com/en-us/ef/ef6/fundamentals/configuring/connection-strings which gives some details about how a DbContext is finding its connection string. What is the class name for your context ? 

    Tuesday, May 14, 2019 2:47 PM
  • User-1128363788 posted

    try maybe https://docs.microsoft.com/en-us/ef/ef6/fundamentals/configuring/connection-strings which gives some details about how a DbContext is finding its connection string. What is the class name for your context ? 

    I tried this article "Use Code First with connection by convention and specified database name" part, yet it didn't work with me.

    Wednesday, May 15, 2019 1:54 PM
  • User-1128363788 posted

    You should try to find the connectstring in the SQL Sever Object Explorer in your Visual Studio not in SSMS.

    I couldn't find the database I want to connect to. Kindly see my reply below your last reply which has the screenshots.

    Wednesday, May 15, 2019 2:02 PM
  • User-1128363788 posted

    I finally solved the error by restarting all sql services from "services.msc" and changing "server" value in my connection string to ".\sqlexpress" which is my server name.

    Wednesday, May 15, 2019 4:27 PM