Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Connection string... C#

Posted on 2014-09-30
4
Medium Priority
?
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

721 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