C# - C Sharp: Kết nối WinForm, WebForm tới SQL Server
Chuỗi kết nối (Connection String) là:
"Server = localhost; Database = tên_db; Integrated Security = True;"
Nếu SQL Server có Named Instance thì cần sửa lại một chút phần Server, cụ thể:
"Server=localhost\phần_named_instance; Database = tên_db; Integrated Security = True;"
Trong trường hợp xuất hiện thông báo lỗi "A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)" thì ta bổ sung vào chuỗi kết nối như sau:
"Server = localhost; database = myStock; Integrated security = true; TrustServerCertificate=True;"