Solved

Connection string... C#

Posted on 2014-09-30
4
162 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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Suggested Solutions

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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