>
KenL.Net  A Developer's Expedition






Skip Navigation Links
Home
Skip Navigation Links
Architecture
Skip Navigation Links
Windows
Skip Navigation Links
Web
Skip Navigation Links
Sharepoint
Skip Navigation Links
Data Development

Web Development

Read Connection String From DLL.config file

using System.Configuration;

using System.Reflection;

 

// Using this class now because it loads the BaseClass.dll.config file to extract

// the connection strings

// The other DAL_DataService class only extracts the config from web.config of the wcf service

       

static Configuration GetDllConfiguration(Assembly targetAsm)

        {

            var configFile = targetAsm.Location + ".config";

            var map = new ExeConfigurationFileMap { ExeConfigFilename = configFile };

            return ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

        }

 

 

// How to use:

 

Configuration config = (Configuration)GetDllConfiguration(Assembly.GetExecutingAssembly());

           

ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

ConfigurationManager.GetSection("connectionStrings");

 

string ConnStr = config.ConnectionStrings.ConnectionStrings[DataBase].ToString();

 

SqlConnection conn = new SqlConnection(ConnStr);




More Recent Web Development Articles:

Read Connection String From DLL.config file
Example on how to read from a DLL's App Config - useful when using class library and you want the library to have its own app.config

Forcing SSL page
How to make a site work in SSL mode and ONLY SSL mode. While still allowing url's that pointed to the site work in secure mode. And also allow for all the other domain names work in SSL mode.

Embed image into email
Don't make your users download images with Outlook... Embed the image...

Email Gridview or DataList
Email contents of a Data GridView or DataList

Basic number formatting specifiers
String formating 101

Making Images - Zip files and FTP
Making images and making zip files made easy. Add in FTP and you have a complete app

Indenty Impersonation
Example of Indenty Impersonation

Get User's Windows login name
Get User's Windows login name

Theading and the Internal Class
How to use threading in your classes

Environmental Variables
How to use Environmental Variables

Simple File watcher
An example of how to wait/watch for files changes

Regex Example
Use Regex to match strings

Using License Providers
add license providers to your code

Using Enumerations
Enumerations are better than using plain integers...

Simple Active Directory Reader
More and more AD is becoming a major part of system development.

Stored Procedure to DataSet
The beloved dataset. Here is an example on how to create and use them.

Exporting a datagrid object's data to Excel
Example on how to send data to Excel

Creating a dataset is simple
Example on how to create and use DataSets

SQL Connection String
How to use SQL connections strings with both Web Applications and Windows Applications

Get User's IP Address
Request the user's IP Address

ASP.Net Listbox and Combobox
How to use ASP.Net Listbox's and Combobox's

WCF with LINQ
Utilze LINQ while working with WCF. This is a good example of using the 3.5 framework



KenL.Net - Home Page of Ken Lovely, MCSE, MCDBA free source code, .NET Development, .NET technology, .NET platform, .NET, Windows Longhorn, longhorn programming, aero, avalon, Indigo, Longhorn, WinFS, WinFX, XAML,Longhorn SDK, C#, C#.NET, C# .NET, CSharp, Windows Longhorn, Whidbey, Visual Studio .NET, XAML, Avalon, Aero, WinFS, WinFX, Avalon, dot net, dotnet, .net, csharp, c sharp, c, sharp, c-sharp, C#, dotnet, VC#, Visual C#, .NET, ASP, ASP+, CSharp, C-Sharp, VB.NET, XML, SOAP, dot net jobs, contracts, books, downloads, software, Java, J#, Visual J#, JSharp, j-sharp, cobol, cobol.net, cobol dot net, speech.net, speech, mobile programming, threading, security, .net security, xml.net, printing, training, dot net training, Tutorials, Articles, Programming, web forms, windows forms, ASP.NET, Web services, XML Web services, Visual studio .net, VC++.NET, managed extensions in C++, MFC, ATL, COM, COM+, DCOM, Pocket PC, Embedded& developement, JScript .NET, VBScript .NET, Mono Project, Eiffel .NET, Windows CE .NET, Magazines, ADO.NET, Cryptography, Active Directory, DirectX, Exception Handling, GDI+, GDI, Strings, Arrays, C# Language, Applied .NET, ken lovely, mcse, mcad, mcsd, mcdba