On Visual Studio remote server is added but can't access databases in that server.
On clicking "Test Connection" it shows this error:
Login failed .The login is from an untrusted domain and cannot be used with Windows Authentication
How to establish a connection to a remote SQL Server database using Visual Studio?
To create a data connection to a SQL Server database:
The Cooler Syntax Way:
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "connection_string";
conn.Open();
// use the connection here
conn.Close();
conn.Dipose();
Executing commands:
SqlCommand command = new SqlCommand("SELECT * FROM TableName", conn);
Also, are running a server manager like XAMP or WAMP ?
It seems that the SQL Server and the development computer belong to different AD domains that do not have a trust relationship. A trust relationship between domains is used so that you can log into computers with accounts from a trusted domain.
If you cannot add a trust relationship between the domains (you might need to ask your IT department for this), you can use SQL authentication to create accounts on the SQL Server that you can use in the connection string. A typical connection string looks like this:
Data Source=MyServer\MyInstance;Initial Catalog=MyDatabase;User Id=MySQLAccount;Password=MyPassword;
As you see from the sample above, a big advantage of using Windows authentication is that you do not have to store the password in the connection string. If using SQL authentication, it is strongly advised to encrypt the connection strings.
See this link on how to configure Mixed authentication mode on a SQL Server so that you can use SQL authentication.
There is a special account usually called sa
. This is the sysadmin account that has all permissions. While a good account for testing authentication issues, it is advised to not use it in applications as a potential attacker could use this account to damage a SQL server installation heavily.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.