Solved

Connection string... C#

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

679 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