Solved

Connection Strings

Posted on 2007-11-28
4
496 Views
Last Modified: 2008-02-01
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
Comment
Question by:cybernation989
  • 2
4 Comments
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20364235
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
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 250 total points
ID: 20364238
0
 
LVL 7

Expert Comment

by:Infinite_Recursion
ID: 20364702
this is funny, why don't you just post the whole exam to save us time
0
 
LVL 5

Assisted Solution

by:rajups
rajups earned 250 total points
ID: 20365020
Hi,
1 is the correct answer.

All the best,
Raju P. S
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now