Lỗi không có server name trong sql 2023 năm 2024

This Error Message Article explains the Microsoft SQL Server Management Studio error message “Cannot connect to [Server Name\SQL Instance]. Additional Information: A network-related or instance specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 28 – Server doesn’t support requested protocol) (Microsoft SQL Server)” and details how to fix the underlying problem that caused it to appear.

Explanation

This message indicates that an instance of SQL Server cannot be opened. One cause is that the instance of SQL that is being contacted does not have the correct Network Protocol enabled. The default values installing SQL Express is to have TCP/IP Network Protocol disabled.

Solution

Enable TCP/IP Network Protocol on the SQL Server.

Note: unless there are specific reasons, you should enable all 3 protocols; Shared Memory, Named Pipes and TCP/IP.

Lỗi không có server name trong sql 2023 năm 2024

Error Message First Appeared: Windows 7 using SQL Management Studio 2008 connecting to SQL 2012 running Windows Server 2008.

Đảm bảo rằng kết nối từ xa với SQL Server đã được kích hoạt. Để kiểm tra cài đặt này, làm theo các bước sau:

  • Mở SQL Server Management Studio.
  • Nhấp chuột phải vào máy chủ và chọn Properties từ menu.
  • Trong hộp thoại Server Properties, chọn mục Connections.
  • Kiểm tra ô chọn “Allow remote connections to this server.

Phương pháp xác thực

Nên cấu hình SQL Server để sử dụng chế độ xác thực kết hợp. Để kiểm tra và thiết lập chế độ xác thực của SQL Server, thực hiện các bước sau:

  • Mở SQL Server Management Studio.
  • Nhấp chuột phải vào máy chủ và chọn Properties từ menu.
  • Trong hộp thoại Server Properties, chọn mục Security.
  • Đảm bảo rằng Server Authentication đã được đặt thành “SQL Server and Windows Authentication Mode.

Sử dụng Drive File

Sử dụng một tệp driver cũng có thể giúp khắc phục lỗi không connect được SQL server. Dưới đây là cách thực hiện:

  • Mở ứng dụng VP và chọn Tools > Database > Database Configuration.
  • Sau khi bạn đã chọn ngôn ngữ, máy chủ (server), và driver, nhấp vào biểu tượng mũi tên xuống màu xanh ở cạnh trường “Driver file.
  • Tải xuống tệp driver: Lưu ý rằng để có thể sử dụng tệp driver, bạn có thể cần quyền tải xuống và cài đặt. Trong trường hợp này, người dùng có thể cần nhấp chuột phải vào biểu tượng ứng dụng VP và chọn “Run as administrator” để đảm bảo có đủ quyền.
  • Nếu một số tệp driver không được tải tự động, bạn cũng có thể nhấn vào biểu tượng ba dấu chấm (…) ở cạnh trường “Driver file” để chỉ định tệp mà bạn muốn sử dụng để thiết lập kết nối với máy chủ SQL.

File Adapter (Dành cho ngôn ngữ .NET)

Nếu bạn sử dụng một tệp Adapter không tương thích, bạn có thể gặp lỗi không connect được SQL server. Để đơn giản hóa việc tải một tệp Adapter tương thích, làm theo các bước sau:

  • Mở ứng dụng VP và chọn Tools > Database > Database Configuration.
  • Sau khi bạn đã chọn ngôn ngữ .NET và MS SQL Server là máy chủ (server), nhấp vào biểu tượng mũi tên xuống màu xanh ở cạnh trường “Adapter file.”
  • Ứng dụng VP sẽ tự động tải xuống tệp Adapter.

Lưu ý rằng để ứng dụng VP có thể tải xuống và cài đặt tệp trình điều khiển, nó sẽ cần chạy với quyền hạn đủ. Bạn có thể cần nhấp chuột phải vào biểu tượng ứng dụng VP và chọn “Run as administrator” để đảm bảo rằng nó có đủ quyền.

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Use the server name parameter in a connection string to specify the client network library

  • Bài viết
  • 06/20/2023

Trong bài viết này

Summary

This article describes how to programmatically specify the client network library in the connection string when you connect to a SQL Server database.

In Microsoft Data Access Components (MDAC) 2.6 and later, you can specify the client access library by using the server name parameter in connection string. Therefore, you can specify a specific client access library when you are prompted by an application for a server name to which to connect. This behavior can be useful when you are testing and troubleshooting connectivity issues for SQL Server.

For example, you can use the Osql command-line utility to connect to SQL Server and to force it to use the TCP/IP network library:

osql -Stcp:myServer,portNumber -E

Original product version: SQL Server Original KB number: 313295

Code Sample

The following Microsoft Visual C# .NET code sample demonstrates how to set the connection string. The connection string has the same format irrespective of the language that you use:

using System;
using System.Data;
using System.Data.SqlClient;
namespace getCurrentProtocol
{
    /// 
    /// Main Application Driver Class
    /// 
    class Driver
    {
        static void Main(string[] args)
        {
            string sCxn = "server=myServer;Integrated Security=SSPI; database=master";
            //string sCxn = "server=np:myServer;Integrated Security=SSPI; database=master";
            //string sCxn = "server=tcp:myServer;Integrated Security=SSPI; database=master";
            //string sCxn = "server=rpc:myServer;Integrated Security=SSPI; database=master";
            //string sCxn = "server=lpc:myServer;Integrated Security=SSPI; database=master";
            string sCmd = "SELECT net_library from sysprocesses where spid=@@spid";
            SqlConnection cxn = new SqlConnection(sCxn);
            SqlCommand sqlCmd = new SqlCommand(sCmd, cxn);
            SqlDataAdapter sqlDa = new SqlDataAdapter(sCmd, cxn);
            DataTable dt = new DataTable();
            try 
            {
                sqlDa.Fill(dt);
                Console.WriteLine("Hit ENTER to continue ...");
                Console.ReadLine();
                foreach (DataRow dr in dt.Rows)
                Console.WriteLine(dr["net_library"]);
            } 
            catch (SqlException e)
            {
                Console.WriteLine(e.StackTrace);
                Console.WriteLine("SQL Error Number: " + e.Number);
                Console.WriteLine("SQL Error Message: " + e.Message);
            }
        }
    }
}

Note

The connection string and particularly the value of the server parameter:

string sCxn = "server=myServer;Integrated Security=SSPI; database=northwind"

Use the Code Sample with Various Network Libraries

The following code samples demonstrate how to use the value of the server parameter to specify various network libraries:

  • TCP/IP:

    server=tcp:hostname

    You can optionally specify a specific port number. By default, the port is 1433.

    server=tcp:hostname, portNumber

  • Named Pipes:

    server=np:hostname

    You can optionally specify a specific named pipe.

    server=np:\hostname\pipe\pipeName

    By default, the pipe name is sql\query. If you connect to a named instance, the pipe name is typically in the following format:

    MSSQL$instnaceName\sql\query

The default value of the underlying protocol is determined by the operating system settings where a protocol can have any one of the following values: