问题
I am using c# to connect to sql server on another computer on the network but i got an exception message Login failed for user ' username' however the server log state that the connection is successful for the user using windows authentication my connection string is:
"Data Source=ipaddress,1433;Initial Catalog=database;Trusted_Connection=True;Integrated Security=False;Connect Timeout=30;user ID=username;password=password"
I am using microsoft sql server 2008 R2
Thanks in advance
回答1:
There are few things you should check:
Remove "Trusted_Connection=True;" in your connection string
Turn off the firewall on both machines for testing. If it works, you can enable the both of them and then configure the access rights for specific application
Enable SQL Authentication on SQL Server instance: http://kbase.gfi.com/showarticle.asp?id=KBID002804
Simple way to test it works or not without running your c# code: you can install the SQL Management Studio on the code-machine and try to connect the SQL Server instance.
Hope it helps.
回答2:
Manage sa account in sql server with username= sa and set password=---- Use this connection string where 1433 is TCP Port
(Server=server_name,1433;Database=------;User ID=sa; Password=-----");
来源:https://stackoverflow.com/questions/9738629/connecting-to-sql-server-from-another-computer