Search code examples
sql-serversqlconnection

Connecting to MSSQL Server via remote client with c#


Well, after doing some research i created a database in MSSql server (2014) and can get a connection via sqlconnection with client, by using:

SqlConnection cn = new SqlConnection("user id = myUSER; password=myPASSWORD;server=mySERVER; Trusted_Connection=yes; database=myDatabase; connection timeout=30");

The connecion exist when my client is local and run on the same machine as MSSQL server, but when i'm on a remote pc i can't connect to the MSSQL server using sqlconnection. How can i connect to that server from remote using sqlconnection - c# ?


Solution

  • Most likely, your SQL Server is not configured to allow remote connections, as Sean Lange points out in one of the comments above.

    Carry out these steps from the Management Studio:

    • Right-click on the server name, click on 'Properties'. You'll get the 'Server Properties' window.
    • Click on the 'Connections' tab in the left of this window
    • You'll see a section on the right, that says 'Remote server connections'
    • Check the 'Allow remote connections to this server' checkbox.

    Allow remote connections to this server