问题
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:
2.221.1.145is a strange IP address. That's not a intranet address, its an internet address. But that is not your primary issue hereYour 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)
Add a
SQL User(not windows user) to your server with loginAndyand passwordmypassUse 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