Read Connection String From DLL.config file
using System.Configuration;
using System.Reflection;
?xml:namespace>
// 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);
}
?xml:namespace>
?xml:namespace>
// How to use:
?xml:namespace>
Configuration config = (Configuration)GetDllConfiguration(Assembly.GetExecutingAssembly());
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationManager.GetSection("connectionStrings");
?xml:namespace>
string ConnStr = config.ConnectionStrings.ConnectionStrings[DataBase].ToString();
?xml:namespace>
SqlConnection conn = new SqlConnection(ConnStr);
More Recent Web Development Articles:
Read Connection String From DLL.config fileExample 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 pageHow 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 emailDon't make your users download images with Outlook... Embed the image...
Email Gridview or DataListEmail contents of a Data GridView or DataList
Basic number formatting specifiersString formating 101
Making Images - Zip files and FTPMaking images and making zip files made easy. Add in FTP and you have a complete app
Indenty ImpersonationExample of Indenty Impersonation
Get User's Windows login nameGet User's Windows login name
Theading and the Internal ClassHow to use threading in your classes
Environmental VariablesHow to use Environmental Variables
Simple File watcherAn example of how to wait/watch for files changes
Regex ExampleUse Regex to match strings
Using License Providersadd license providers to your code
Using EnumerationsEnumerations are better than using plain integers...
Simple Active Directory ReaderMore and more AD is becoming a major part of system development.
Stored Procedure to DataSetThe beloved dataset. Here is an example on how to create and use them.
Exporting a datagrid object's data to ExcelExample on how to send data to Excel
Creating a dataset is simpleExample on how to create and use DataSets
SQL Connection StringHow to use SQL connections strings with both Web Applications and Windows Applications
Get User's IP AddressRequest the user's IP Address
ASP.Net Listbox and ComboboxHow to use ASP.Net Listbox's and Combobox's
WCF with LINQUtilze LINQ while working with WCF. This is a good example of using the 3.5 framework