Search code examples
c#sql-servervisual-studio-2017mdf

Login failed for user domain\user in vs17


I have tried to open a mdf-file getting the Loging failed for user domain\user. ConnectionString to the existing mdf-file

<add name="NWindConnectionString" connectionString="data source=(localdb)\mssqllocaldb;attachdbfilename=|DataDirectory|\NWind.mdf;integrated security=True;connect timeout=120" providerName="System.Data.SqlClient" />

I tried to create a mdf-file with visual studio 2017 in a .NET MVC5 project getting the Loging failed for user domain\user.

I have installed SQL Server 2014. I can connect perfectly to the SQL Server Management Studio with my windows credentials. SQL Server is configured to use Windows credentials.

I opened the mdf-file of the project (is a GitHub project) correctly with SQL Server Managment Studio attaching the file.

Steps to add new MDF-File to the project:

Add New Item into App_Data folder

Service-based Database -> Button Add

Then error promps

To get an idea which process I am following https://www.linkedin.com/pulse/service-based-database-file-visual-studio-bharath-gunupati

Attempt to open an existing mdf-file(NWind.mdf) in my project enter image description here

Any clue what can be wrong with Visual Studio 17? Could Be a misconfiguration of the Visual Studio?

For now I uninstalling SQL Server 2014 and installing SQL Server 2017, hope that this fix some misconfiguration of Visual Studio.

After install and unistall still not working


Solution

  • I found the solution.

    Apparently the sql server localdb installed with visualstudio was damage or something. So I run this on command line window.

    sqllocaldb stop mssqllocaldb
    sqllocaldb delete mssqllocaldb
    sqllocaldb start "MSSQLLocalDB"
    

    Although, my Visual Studio needed a complement to connect properly with SQL Server.

    This is what actually fixed my login for user error.

    In case you guys require this Complement for Visual Studio 2017 complement, but not sure if that was part of the solution.