Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 27th, 2007, 11:57 PM
Authorized User
 
Join Date: Feb 2007
Location: Bend, Oregon, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using DB Connection from Config file

Is it possible to use the DB connection stored in the webconfig file in a codepage?

I am trying to use a datareader but do not want to redeclare the connection string in the code file.

If this is possible I would appreciate an example of how to call it.

thanks

 
Old March 28th, 2007, 06:18 AM
Authorized User
 
Join Date: Dec 2006
Location: , , India.
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Sunnys Send a message via Yahoo to Sunnys
Default

use
sqlconnection connection=new sqlconnection();
connection.ConnectionString = ConfigurationManager.ConnectionStrings["name"].ConnectionString;

here name will be the name key of web.config file

enjoy :)




Similar Threads
Thread Thread Starter Forum Replies Last Post
how to config db connection in a DSN-less server congfuzi Dreamweaver (all versions) 4 June 27th, 2008 06:45 PM
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 08:07 AM
Using Connection Strings - App.config testsubject Visual Studio 2005 1 July 16th, 2007 01:08 AM
setting connection string in the web.config ACE2084 ADO.NET 2 January 6th, 2005 04:33 PM
Database Connection with Web.Config RPG SEARCH Classic ASP Databases 7 July 26th, 2004 06:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.