I can't access the database with my login through visual studio. I can login and access the database with MSQL Server MS though (Authentication - SQL server authentication).

This was not a problem before I synced together with a few other projects, but I can't find where I am going wrong, maybe I am missing a connection or something. I got the Login failed for user ' ' error at Database.Initialize(true);.

My connection string in web.config is as below:

<connectionStrings>
    <add name="Hololens" connectionString="Server=tcp:adress.net,1433;
         Initial Catalog=HololensDB;Persist Security Info=False;User ID=HololensUser;Password=hololens;MultipleActiveResultSets=False;Encrypt=True;
         TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient"/>
  </connectionStrings>

Does anyone know how can I solve this? Or why this error is occurring now but not before?

2 Answers

0
FearlessFox On Best Solutions

After trying every possible solution we could think of, I finally decided to delete the database in SSMS and run the contextInitializer again. This actually worked, there was no longer an Login failed for user-error.

Without looking into this matter further I figured that maybe my user was not allowed to drop or create the database or something - this because the initializer has DropOrCreateIfModelChanges.

Still this was not explained in the login failure error. Thanks for the help!

0
Bart Hofland On

I am not sure if it solves the issue, but I think the connection string should not contain any line breaks.

Please keep the entire connectionString attribute value in a single line and try again.

<connectionStrings>
    <add name="Hololens"
         connectionString="Server=tcp:adress.net,1433;Initial Catalog=HololensDB;Persist Security Info=False;User ID=HololensUser;Password=hololens;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
         providerName="System.Data.SqlClient"/>
</connectionStrings>