Login failed for user 'NT AUTHORITY\NETWORK SERVICE'

后端 未结 9 1367
北海茫月
北海茫月 2020-11-29 04:23

I been strugling with this for 2 days now without comming any closer to solution. I have read 20-30 threads alteast and stil can not resolve this.

Please help me out

相关标签:
9条回答
  • 2020-11-29 04:57

    The SQL Server login required is DOMAIN\machinename$. This is the how the calling NT AUTHORITY\NETWORK SERVICE appears to SQL Server (and file servers etc)

    In SQL,

    CREATE LOGIN [XYZ\Gandalf$] FROM WINDOWS
    
    0 讨论(0)
  • 2020-11-29 05:01

    The error message you are receiving is telling you that the application failed to connect to the sqlexpress db, and not sql server. I will just change the name of the db in sql server and then update the connectionstring accordingly and try it again.

    Your error message states the following:

    Cannot open database "Phaeton.mdf" requested by the login. The login failed.
    

    It looks to me you are still trying to connect to the file based database, the name "Phaeton.mdf" does not match with your new sql database name "Phaeton".

    Hope this helps.

    0 讨论(0)
  • 2020-11-29 05:08

    You said it worked fine when you were using SQL Express edition. By default express editions create a named instance & run in NT Authority\Network Service.

    SQL Server STD by default install a default instance & run in NT Authority\SYSTEM.

    Do you have both the full SQL edition & Express edition installed on the same machine?

    1. It could be that somewhere the connection string still refers to the Named instance 'SQLEXPRESS' rather than the default instance created by the full version.

    2. Also where is the connection string defined? In IIS or your code? Make sure that if defined in many places, all point to same SQL instance & database.

    3. Also try looking at the detailed error present in the SQL Server error logs. The error logged in event log are not complete for secuirty reasons. This will also help you to know if the connection was made to the correct SQL Server.

    4. Also make sure that the machine on which SQL is installed is accessible & IIS is trying to access the same machine. In my company sometimes due to wrong name resolution, the query fails since most of our computers have SQL installed & the query lands in the wrong SQL Server.

    5. Make sure that the database exists in the SQL Server. The name displayed under databases in SQL Management Studio should match that in the connection string.

    0 讨论(0)
  • 2020-11-29 05:09

    I liked Jed's solution but the issue with that was every time I built my project in debug mode, it would deploy my database project and removed the user again. so I added this MySQL script to the Post-Deployment script. it practically does what Jed said but creates the user every time I deploy.

    CREATE USER [NT AUTHORITY\NETWORK SERVICE]
        FOR LOGIN [NT AUTHORITY\NETWORK SERVICE]
        WITH DEFAULT_SCHEMA = dbo;
    Go
    
    EXEC sp_addrolemember 'db_owner', 'NT AUTHORITY\NETWORK SERVICE'
    
    0 讨论(0)
  • 2020-11-29 05:13

    If the error message is just

    "Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.", then grant the login permission for 'NT AUTHORITY\NETWORK SERVICE'

    by using

    "sp_grantlogin 'NT AUTHORITY\NETWORK SERVICE'" 
    

    else if the error message is like

    "Cannot open database "Phaeton.mdf" requested by the login. The login failed. Login failed for user 'NT AUTHORITY\NETWORK SERVICE'."

    try using

    "EXEC sp_grantdbaccess 'NT AUTHORITY\NETWORK SERVICE'" 
    

    under your "Phaeton" database.

    0 讨论(0)
  • 2020-11-29 05:14

    The Best way is to create a user for your application and assign the permissions that are suitable for that user. Dont use 'NT AUTHORITY\NETWORK SERVICE' as your user it has its own vulnerability and it is a user that has permissions to so many things on the OS level. Stay away from this built in user.

    0 讨论(0)
提交回复
热议问题