Solved

Connection string... C#

Posted on 2014-09-30
4
160 Views
Last Modified: 2014-10-08
I have a connection string that is on my web config file that work correctly but Im trying to re write it as a different format.. Need some help on that one.

Old format:
 <add name="DropDownConnectionString" connectionString="Data Source=SVSQ02\macomb_test;Initial Catalog=DropDown;Integrated Security=True"
      providerName="System.Data.SqlClient" />

Open in new window


New format: Not sure what to put it in here...
  SqlConnection amd = new SqlConnection();
        amd.ConnectionString="????????";
0
Comment
Question by:yguyon28
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40353284
Add a reference to System.Configuration.dll:

using System.Configuration;

...

amd.ConnectionString = ConfigurationManager.ConnectionStrings["DropDownConnectionString"].ConnectionString;

Open in new window

0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 40353910
Hi yguyon28,
 
using System.Configuration;

First you have to add reference to the webpage and then

//Get connection string from web.config file

string strcon =
ConfigurationManager.ConnectionStrings["DropDownConnectionString"].ConnectionString;

//create new sqlconnection and connection to database by using connection string from web.config file

SqlConnection con = new SqlConnection(strcon);
con.Open();
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40354331
@TAPAN PATTANAIK

Isn't that what I said...5 hours earlier?
0
 
LVL 21

Expert Comment

by:Tapan Pattanaik
ID: 40354337
Hi kaufmed,

Sorry, I had not seen your answer that time.

Regards,
Tapan Pattanaik.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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