TAILIEUCHUNG - Using a SqlConnection Object to Connect to a SQL Server Database phần 1

Using a SqlConnection Object to Connect to a SQL Server Database You create a SqlConnection object using the SqlConnection() constructor. This constructor is overloaded | Using a SqlConnection Object to Connect to a SQL Server Database You create a SqlConnection object using the SqlConnection constructor. This constructor is overloaded meaning that there are multiple versions of the constructor that you can call. The SqlConnection constructors are as follows SqlConnection SqlConnection string connectionString where connectionString contains the details for the database connection. You ll learn the details of the connectionString in this section. Assuming you ve imported the namespace you can create a new SqlConnection object using the following statement SqlConnection mySqlConnection new SqlConnection You can then set the details for the database connection using the ConnectionString property of mySqlConnection. For example server localhost database Northwind uid sa pwd sa where server specifies the name of the computer on which SQL Server is running. database specifies the name of the database. uid specifies the name of the database user. pwd specifies the password for the user. Warning For security reasons do not include the username password in your production code. Instead ask the user to enter their name and password-or use integrated security which you ll learn about shortly. One thing you need to bear in mind is that you can set the ConnectionString property only when your Connection object is closed. You can also pass a connection string directly to the SqlConnection constructor. For example string connectionString server localhost database Northwind uid sa pwd sa SqlConnection mySqlConnection new SqlConnection connectionString Or more simply SqlConnection mySqlConnection new SqlConnection server localhost database Northwind uid sa pwd sa You can set an optional connection timeout which specifies the number of seconds that the Open method will wait for a connection to the database. You do this by specifying a connection timeout in your connection string. For example the

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.