Connection string for SQL Server Express on remote Computer login failed error

☆樱花仙子☆ 提交于 2019-12-08 05:28:45

问题


I recently asked the question at this address:

Remote SQL Server connection string

That thread has helped us arrive at this connection string:

SqlConnection connection= new SqlConnection("Server=2.221.1.145;Database=Database;User Id=Andy-PC\\Andy;Password=mypass");

This throws the error:

Login failed for user 'Andy-PC\Andy'

This user owns the database and i guess should have access to it....however I remember when trying this style of authentication locally it did not work - which is why I originally started with Integrated Security=true. Is there something specific I need to do to add this user to the SQL Server, or the Database?


回答1:


I see a few issues:

  1. 2.221.1.145 is a strange IP address. That's not a intranet address, its an internet address. But that is not your primary issue here

  2. Your connection string is using SQL logins, not windows (trusted) logins. So your user id should not have a domain in front of it.

Assuming you want to use SQL Logins (these can be simpler to troubleshoot)

  1. Add a SQL User (not windows user) to your server with login Andy and password mypass

  2. Use this connection string: Server=2.221.1.145;Database=Database;User Id=Andy;Password=mypass




回答2:


Finally worked it out.

Turning the security to be both Windows and SQL authentication. Then following : How can I create a user in SQL Server Express database I added to my project? followed by GRANT EXECUTE to all stored procedures fixed us up with exactly what we needed!




回答3:


Usually this error occurs when the machine on which the application has been running not having the access to Andy-PC\Andy.

We should use domain specific account instead of machine specific accounts when we need to use windows authentication.

Otherwise we have to use SQL authentication.



来源:https://stackoverflow.com/questions/24541681/connection-string-for-sql-server-express-on-remote-computer-login-failed-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!