Quantcast
Channel: ASPRunner forums
Viewing all articles
Browse latest Browse all 2586

[SOLVED] get connection string from Web.Config or other source

$
0
0
In the after init event ASP .NET Ver 9.8 c# looking to pull/get the DB connection string from the Web.Config or some other source.

I tried the following in the event code

// Addding the required Microsoft reference
using System.Configuration;

// then calling the appropriate method to get the connection string
string cs = ConfigurationManager.ConnectionStrings["connectionStringName"].ConnectionString;

however this isn't working as the Microsoft reference needs to be added as part of the event prior to any code

So Check out the SOLVED solution at the end of this post..

I put together all the pieces of the puzzle into a nicely documented, guaranteed to work code example

Just cut and paste and have at it...

Best
Fellow ASP Runner .NET user 4 + yrs and running... ( no pun intended... )

Viewing all articles
Browse latest Browse all 2586