Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

Connection Strings

This is not an exam or homework

You have created the following connection string entry in the web.config:
<connectionStrings>
<add name="TestConnectionString" connectionString="Data Source=Test;Datbase=Test;UID=google;Password=google" providerName="System.Data.SQLClient"/>
<connectionStrings>

Which of the following code segments reads the connection string information from the web.config and assigns it to a SQLConnection object?

1.
Imports System.Configuration
Imports System.Data.SqlClient
...
Dim con As New SqlConnection
con.ConnectionString = ConfigurationManager.ConnectionStrings("TestConnectionString")
 
2.
Imports System.Configuration
Imports System.Data.SqlClient
...
Dim con As New SqlConnection
con.ConnectionString = ConfigurationManager.RetrieveConnectionString("TestConnectionString")
 
3.
Imports System.Configuration
Imports System.Data.SqlClient
...
Dim con As New SqlConnection
con.ConnectionString = ConfigurationManager.GetConnectionString("TestConnectionString")
 
4.
Imports System.Configuration
Imports System.Data.SqlClient
...
Dim con As New SqlConnection
con.ConnectionString = ConfigurationManager.ConnectionStrings("TestConnectionString").ConnectionString
0
cybernation989
Asked:
cybernation989
  • 2
2 Solutions
 
Pratima PharandeCommented:
Dim rootWebConfig As System.Configuration.Configuration
    rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/MyWebSiteRoot")
Dim connString As System.Configuration.ConnectionStringSettings
If (0 < rootWebConfig.ConnectionStrings.ConnectionStrings.Count) Then
    connString = rootWebConfig.ConnectionStrings.ConnectionStrings("NorthwindConnectionString")
    If Not (Nothing = connString.ConnectionString) Then
        Console.WriteLine("Northwind connection string = {0}", connString.ConnectionString)
    Else
        Console.WriteLine("No Northwind connection string")
    End If
End If
0
 
Pratima PharandeCommented:
0
 
Infinite_RecursionCommented:
this is funny, why don't you just post the whole exam to save us time
0
 
rajupsCommented:
Hi,
1 is the correct answer.

All the best,
Raju P. S
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now