0

I'm working in Visual Studio 2012 and trying to connect my website to an mdf database file (sisgar.mdf):
enter image description here

I have tried to connect with this code:

 @{
  var base_dados = Database.Open("sisgar");
  string query = ("select * from tb_porteiro");
   var resultados = base_dados.Query(query);

<table>
    @{
    foreach ( var linha in resultados )
    {
      <tr>
          <td>@linha.idp </td>
          <td>@linha.porteiro </td>
      </tr>
    }
    }

The mdf is in the right folder, the table exists, have the fields
enter image description here

Return this error
enter image description here

Exists another way to connect to the mdf

Thom A
  • 88,727
  • 11
  • 45
  • 75
alejandro carnero
  • 1,774
  • 7
  • 27
  • 43
  • [Please do not upload images of code/data/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Thom A Oct 04 '22 at 08:37

1 Answers1

0

Solution

  1. Open Task Manager and look for sqlsrv.exe process and end it

  2. Delete all files in the

    %LOCALAPPDATA%\Microsoft\Microsoft SQL Server Data\SQLEXPRESS 
    

    folder

  3. Then run again.

For more details, you can check the posts below:

1. Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance.

2. Error: Failed to generate a user instance of SQL Server

Workaround

If the solution not works for you. Please try to attach your mdf file to your sql server.

Jason Pan
  • 15,263
  • 1
  • 14
  • 29