Current location - Health Preservation Learning Network - Healthy weight loss - The connection to the named instance sqlexpress on the host localhost failed.
The connection to the named instance sqlexpress on the host localhost failed.
There are two situations, one is when SQL Server 2005 is opened, and the other is when the application is connected to SQL Server 2005. To sum up, there are several reasons:

1. The database engine is not started.

There are two ways to start:

(1) start->; Program-> Microsoft SQL Server 2005-& gt; SQL Server 2005 peripheral application configurator, click "Connect the peripheral application configurator for service" in the opened interface, find the database engine in the opened interface, and click "Service" to see if it has been started. If it has not been started, click "Start" to ensure that the "Start Type" is automatic, not manual, otherwise it will be started manually next time;

(2) Openable: Start-> Program-> Microsoft SQL Server 2005-& gt; Configuration tool->; SQL Server Configuration Manager, select SQL Server(MSSQLSERVER) in SQL Server 2005 service, and click the "Start Service" button in the toolbar to change the service status to start;

When using the above two methods, sometimes there may be errors when starting, so it is necessary to check whether the network configuration of SQL Server 2005 has enabled VIA in MSSQLSERVER protocol in SQL Server 2005 Configuration Manager >, and if so, it is forbidden to use it. Then, just do one of the above operations.

2. Whether to allow remote connection when making remote connection.

By default, SQL Server 2005 is limited to local connections. We can enable remote connection manually. In the first method above, find the database engine, click "Remote Connection", change "Local Connection Only (L)" to "Local Connection and Remote Connection (R)" on the right, and select "Use both TCP/IP and named pipes (B)".

3. If it is a remote connection, also check whether the statement connecting to the database is correct, whether the login account is correct and whether the password is correct.

When I connect to a database in a local area network, because there is something wrong with the connection string, when a computer in the local area network connects to a database on another computer, I put server= another computer's IP with the database. I always get the above error when I connect to the database. I checked it for a long time. Later, I found that IP was not transmitted to the connection string correctly. Originally, I used local connection, that is, 127.

The above is my summary, hoping to provide some help and reference for friends who encounter similar problems.