70-526VB: Integrating Data in a Forms Application

These questions are based on 70-526VB: TS: Microsoft .NET Framework 2.0 – Windows-Based Client Development (VB.NET) Microsoft Self Test Software Practice Test.

 

Objective: Integrating Data in a Windows Forms Application
Sub-Objective: Manage connections and transactions.

 

Single Answer, Multiple Choice

 

You are an application developer for a company. You are creating a Windows application that will be used by the employees of your company to manage SQL Server database Sales.

 

The Sales database is stored on a Microsoft SQL Server 2005 instance named SqlServer1. As per your database administrator’s recommendation, to manage SqlServer1 instance performance, the maximum number of connections to the SqlServer1 instance should be 100.

 

You decide to establish a connection with the Sales database and implement connection pooling.

 

Which code should you use to establish the connection with the Sales database?

 

 

  1. 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()
  2. Dim con As New System.Data.SqlClient.SqlConnection
    con.ConnectionString = “Data Source=SqlServer1;” & _
    “Integrated Security=true;Initial Catalog=Sales;” & _
    “Pooling=true;”
    con.Open()
  3. 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=0″
    con.Open()
  4. Dim con As New System.Data.SqlClient.SqlConnection
    con.ConnectionString = “Data Source=SqlServer1;” & _
    “Integrated Security=true;Initial Catalog=Sales;” & _
    “Pooling=true;Max Pool Size=1;Min Pool Size=100;”
    con.Open()

 

Answer:
A. 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()

 

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 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:
MSDN Library > .NET Development > .NET Framework SDK > Class Library Reference > System.Data.SqlClient > SqlConnection Class > SqlConnection Properties > ConnectionString Property

Like what you see? Share it.Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone
cmadmin

ABOUT THE AUTHOR

Posted in Archive|

Comment: