c#


How to make the connection string visible throughout the solution (across layers)?


I have developed an Asp.net application using three tire architecture and i am reading the connetions string from web.conf file in the UI layer,
My problem is i have to pass the connection string as a parameter in all the functions that are in the Bo layer.
Is there any work around for making the connection string visible throughout the Bo layer so that i dont need to send the connetions string as parameter in all my method calls.
Include the System.Configuration reference to all projects in which you want to access the connection string and use the following code to access your connection string.
ConfigurationManager.ConnectionString["MyConnection"].ConnectionString
It is advisable to use a helper class to access your connection string.
internal sealed class Utility
{
public static string MyConnectionString{
get{
return ConfigurationManager.ConnectionString["MyConnection"].ConnectionString;
}
}
}
This will help you to move your connection string from web.config to any other location in future without breaking your code.

Related Links

Error “Object Reference not set to an Instance of an object” on read from DataGrid
How to format number into ten thousands [duplicate]
Error Linq to Entities Datetime
Display random number and sorting
Difference between function and method [duplicate]
Wpf Extended Toolkit: DateTimePicker
Assigning different variables with similar name in a loop
how to convert odbc connection to sql connection?
Need header node height of TreeViewItem
multiple linq orderby not working
How to set a Excel cell's value type to Text in C#?
Binding not working with row header on DataGrid
Setting DataGridCell style trigger property not responding
installing window service using command prompt
SignalR send object from client to server is not deserialized correctly
Why is my object destructed only once when serializing it from another app domain?

Categories

HOME
drupal
gulp
stanford-nlp
leaflet
intellij-idea
gaussian
spss
salesforce-lightning
grid
opacity
scapy
osrm
websharper
mbed
browsermob
derby
github-flavored-markdown
hql
infopath
smooth-scrolling
android-actionbar
alert
geography
indri
single-page-application
serenity-js
multipart
infinite-loop
email-client
scalatest
windows-mobile
gulp-jshint
marionette
sqldependency
request-uri
dynamics-ax-2012-r3
recreate
r-factor
overflow
opencsv
ng2-bootstrap
traitsui
restler
wit-ai
aweber
border-layout
strategy-pattern
anypoint-studio
stdin
lex
blueimp
file-conversion
mixed-models
binary-decision-diagram
chrome-custom-tabs
rivets.js
denodo
ionic2-select
jscoverage
perldoc
openpgp.js
multi-targeting
jtextarea
android-tabs
gdi
phpdesigner
calc
videoview
yfiles
recode
tvp
sdkman
gitk
biginsights
pdcurses
page-refresh
parseexception
applinks
chunks
selenium-grid2
javacompiler
dotcmis
imaplib
php-amqplib
kademlia
asp.net-4.0
removeall
symbian3
blotter
antixsslibrary
django-tinymce
rfc822
bindinglist
copyfile
zend-validate
service-layer
javah
text-manipulation
pkcs#7
focus-stealing
ffdshow

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App