Solved

Connection string... C#

Posted on 2014-09-30
4
157 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 74

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 74

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

13 Experts available now in Live!

Get 1:1 Help Now