C# SQL Server

sn3rd

Expert Member
Joined
Jan 18, 2008
Messages
4,305
Reaction score
11
Thought I'd get in on all the recent C# action :)

I am unable to connect to an SQL Server on another machine. It allows me to connect locally (the code, run from the other machine with server=localhost works), but not from a remote machine. Sometimes it times out, other times it says
Connecting... System.Data.SqlClient.SqlException: Login failed for user ''. The user is not associated with a trusted SQL Server connection.

I am using SQL Server Management Studio. Remote connections are enabled.

Again, the same code transplanted and run on the server works. :confused:
 
Configure the SQL Server you are connecting to to allow "external TCPIP connections".
It's somewhere in the configuration software.
Then create a proper sql server login and password, give that sql login the appropriate permissions, and use that login and password to connect to the SQL Server.
You may want to make sure that port 1433 is open on the computer hosting the SQL Server as well.
 
What does your connection string look like? Are you using a trusted connection? Try using an explicit username and password to an SQL Server user stored on the server. For testing purposes, try using the "sa" user.

(just NEVER store the sa user's credentials in a production application!)
 
FYI, sa would only work if he installed SQL Server in Mixed Mode. Trusted connection should work if run from the local machine.

I'd suggest keeping a copy of the database on your local machine and leaving the one on the server/live enviroment and "syncing" it every afternoon (if the data changes a lot) or every week or so.

Developing on dummy data is crap, usually real world usage gives you better exposure to possible data-based bugs.

If it's necessary to login remotely then always remember... don't believe the error message ;)

Follow the above advice (of other posters) to double check everything
 
It's also by default not checked in the installation, so n00bs usually just click next ;)
 
Top
Sign up to the MyBroadband newsletter
X