Solved

Connection Strings

Posted on 2007-11-28
4
498 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

932 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

14 Experts available now in Live!

Get 1:1 Help Now