Learn About Upgrade: MCAD Skills to MCTS Windows Applications
By Certification Magazine —
1 | 2 | 3 |
Answer:
A
Tutorial:
You should use the following code:
Dim con As New System.Data.SqlClient.SqlConnection
con.ConnectionString = "Data Source=SqlServer1;" & _
"Integrated Security=true;Initial Catalog=Sales;" & _
"Pooling=true;Max Pool Size=100;Min Pool Size=1;"
con.Open()
This code uses the SqlConnection class to establish a connection with the SQL Server 2005 database named Sales. This code first creates the con object and then sets the ConnectionString property of the con object. The ConnectionString property contains parameters, such as Data Source, User ID, Integrated Security, Password, Initial Catalog, Pooling, Max Pool Size and Min Pool Size. The Data Source parameter specifies the name of the computer on which the database is stored. In this scenario, the SQL Server instance name is SqlServer1; therefore, this code sets the Data Source parameter to SqlServer1.
The User ID parameter specifies the user name to be used. The Password parameter specifies the password of the user specified in the User ID parameter. The Integrated Security parameter is used to specify whether Windows authentication is used or not to establish the connection. The Initial Catalog parameter is used to specify the name of the database that will be accessed by using the SqlConnection object.
In this scenario, you will be using the Sales database. Therefore, this code sets the Initial Catalog parameter to Sales. The Pooling parameter specifies whether connection pooling for the SqlConnection object is enabled or not. The Max Pool Size parameter specifies the maximum number of connections that can be pooled in the connection pool. Your application will discard any requests to establish a connection if the maximum pool size value of a connection pool is reached. In this scenario, you must ensure that the maximum number of connections to the SqlServer1 instance is 100. Therefore, this code sets the Max Pool Size parameter to 100.
The Min Pool Size parameter specifies the minimum number of inactive connections that will be available in the pool at any point in time. If the Min Pool Size parameter contains a value greater than zero, the connection pool is not destroyed until the application is running. This code also uses the Open method of the SqlConnection class. The Open method attempts to establish a connection with the specified SQL Server by using the ConnectionString property parameters.
You should not use the code that does not specify the Max Pool Size and Min Pool Size parameters in the connection string. In this scenario, you must ensure that the maximum number of connections to the SqlServer1 instance is 100. Therefore, you should set the Max Pool Size and Min Pool Size parameters.
You should not use the code that specifies a Min Pool Size parameter value of 0 in the connection string. The Min Pool Size parameter specifies the minimum number of inactive connections that will be available in the pool at any point in time. If the Min Pool Size parameter contains a value greater than zero, the connection pool is not destroyed until the application is running.
You should not use the code that sets the Max Pool Size parameter to 1 and the Min Pool Size parameter to 100 because these values are reversed. In this scenario, you must ensure that the maximum number of connections to the SqlServer1 instance is 100. Therefore, you should set the Max Pool Size parameter value to 100 and the Min Pool Size parameter value to 1.
Reference:




