SoFunction
Updated on 2025-04-05

Detailed explanation of how to configure SQL2008 and allow C# remote external connections

Step 1:Right-click on the server icon, select property, and then select connection, and select allow remote connection. The purpose of this step is to allow remote connection to the database.

Step 2:On the database server icon, expand the directory, find the Logins subdirectory tree under Security, set the properties of the SA account, change password, and in the status bar, select enable login. The purpose of this step is to allow remote clients to use the sa user Duncan, which is the abbreviation of system administrator, has the highest database management permissions, and is disabled by default.

Step3:Right-click on the database server icon and open the Facets option to change the RemoteDacEnabled value to true. The purpose of this step is to allow the establishment of a remote dedicated administrator connection, which has the highest permissions and can establish a DAC connection even if it is not possible to establish a standard connection.

Step4:Turn on the service, open the SQL Server Configuration Tool, open the network configuration, select the TCP/IP protocol, click on the attributes, fill in the IP address of the server where the database is located. If it is a local server, fill in 127.0.0.1.

Test method:
Create a C# Console application source file, the code is as follows:
Copy the codeThe code is as follows:

class Program
    {
        static void Main(string[] args)
        {
            SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123456789;database=MyTable");
            try
            {
                ();          

("Connecting to the database successfully");
            }
            catch
            {
("Cannot connect to database");
            }
            ();
        }
    }

If you can connect normally, it will prompt that the connection is successful.