.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

n-tier, configuration info, specifically connection strings

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :ASP.Net


I have an ASP.NET project which is pretty n-tier, by namespace, but I need to separate into three projects:  Data Layer, Middle Tier and Front End.

I am doing this because... 

A) It seems the right thing to do, and

B) I am having all sorts of problems running unit tests for ASP.NET hosted assemblies.

Anyway, my question is, where do you keep your config info?

Right now, for example, my middle tier classes (which uses Linq to SQL) automatically pull their connection string information from the web.config when instantiating a new data context.

If my data layer is in another project can/should it be using the web.config for configuration info?

If so, how will a unit test, (typically in a separate assembly) provide soch configuration info?

Thank you for your time!


View Complete Post

More Related Resource Links

Package configuration file with multiple connection strings


I am using the configuration file to read the connection string in the SSIS packages. In one of my packages i have to use two different connection strings. If i specify the second connection string in the config file, then the current package works well but other packages fails during validation saying the second connection manager does not exist in the package. Is it not possible to have multiple connection string in a single config file?

Protect It: Safeguard Database Connection Strings and Other Sensitive Settings in Your Code


Protecting application secrets, such as database connection strings and passwords, requires careful consideration of a number of pertinent factors such as how sensitive the data is, who could gain access to it, how to balance security, performance, and maintainability, and so forth. This article explains the fundamentals of data protection and compares a variety of techniques that can be used to protect application settings. The author discusses what to avoid, such as hiding keys in source code and the use of Local Security Authority. In addition, he presents some effective solutions such as the Data Protection API.

Alek Davis

MSDN Magazine November 2003

SQL Server Configuration Manager: Connection to target machine could not be made in a timely fashion

I have a SQL Server 2005 box that was moved from a domain environment to a non-domain environment and was never dropped from its original domain before moving over.  Subsequently a new domain was created at the data center this SQL Server box now resides in.  The machine was dropped from its old domain and joined to the new one.   All the while the service accounts were set to the local admin account.  When I tried to start the Configuration Manager I got the message "Connection to target machine could not be made in a timely fashion.".  I read some blog entries and tried changing all the service accounts to Local System and the error message still came up.   All of the SQL Server services run fine.  It is just this management console that I cannot open.  I wasn't with this employer when this box was moved to the data center so I do not know if it worked prior and there isn't anyone here that could give me its history.   Any help would be appreciated.

SSIS Connection Configuration

Hello,   I have a bunch of packages that use different connections. I would like to put all these connections in the a sql config file and use only the needed connections for that package when executing. Right now when I run a package that doesn't use all the connections in the config table I get errors for all the other connections.   I would like to keep all the connections in one table for easy management, is this possible and even if the package does not use all the connections.   THanks, J

Encrypting connection strings and click-once publishing

Ok, so I've figured out the connection string encrypting.  I can encrypt it and it encrypts the .config file in the bin directory and not the one in the project solution, which makes sense.  Now, I go to publish it though with click-once and I end up getting two versions of the file in  ...\AppData\Local\Apps\2.0\... directory.  One is encrypted and the other is not.  This is unacceptable becuase it leaves the connection string in plain text on the user's computer.  Is there a way around this or some other method of instlling the program that it will also receive automatic updates and not have the unencrypted version floating around with plain text connection strings?

Get user info in infopath using data connection

hi,  i want to use the absence request template form and connect the employee section and manager section to an existing database. what i want to create now in this template is this (i'm going to explain my scenario): - when the user open the infopath absence request form and insert his name, id number etc (employee section), the approver's name and mail addres (manager section) filled automatically. the approver name must be corresponding to the user name. in the existing database there is a table with the approvers name filled for each user, but from there i dont know how to apllicate this table to use for the auto fill. and after the form is ready can i publish it to my wss 3 site collection? is there a tutorial that explain a scenario like this? thnx

How to use Connection Strings from IIS in my c# application


Hello all,

Thanks in advace for your help.

I have a C# web service where I need to access a MS SQL DB. I see a way of creating a connection string in IIS and using it in the web application when connecting to the DB. In IIS in Connection strings you specify the name of the connection, server, user n pwd

How can I use the name of connection string created in IIS in my c# app.?

I am currently using

CustomerInfo customerinfo = new CustomerInfo<

using connection strings in the report server than the datasource in 2005



I am using a datasource in the report server where all the reports use that shared datasource while calling the reports from asp.net pages.

Now, as asp.net pages uses the connection string for the databases which is assigned in the web.config file, i want the reports also use the same connection string because you don't need to change on both places( web.config and report server datasource).

Any idea plz

Package Configuration causing problems with Oracle Connection


Hi All,


We need to import the data from Oracle 10g database to SQL Server 2005 database.

Solution Picked:

In order to accomplish the above, we used SQL Server Integration Services along with Business Intelligence Developer Studio.


Base Details:

There are around 17 packages, each retrieving data from Oracle and storing into SQL Server based on current date. Following are the steps used:

  1. Get current date from SQL Server [Execute SQL Task].
  2. Create Query based on date obtained from step (1) [Script Task].
  3. Based on query obtained from step (2). Inside a [Data Flow Task] following sub actions are performed:

    Actions performed in [Data Flow Task]

  1. Retrieve data from Oracle database using query through [OLE DB Source].
  2. Perform any data modifications to correct the data [Derived Column].
  3. Store data in SQL Server [OLE DB Destination].
  4. Rejections are saved in text file [Flat File Destination].

The configuration of the Admi\Connection\TCP protocol in the SQL Instance is not valid


Hi, I have two node active/active dev cluster with 10 instances installed (sql 2005 dev edition 64bit SP3).  Each node hosts 5 instances. Every time I either move the group or  take it offline I get the following in my even log: The configuration of the AdminConnection\TCP protocol in the SQL instance instancename is not valid.  I checked the TCP/IP properties and all instances are using dynamic ports and all of them are different.  When I restarted SQLBrowser services I got the same alert for 9 instances.  Any suggestions on what to look next. 


Using a pfx certificate to decrypt app.config connection strings


Hi, I am using both Azure & WinForms applications, with common libraries in .NET 4. I have encrypted my connection strings in my Azure app using the approach here: http://blogs.msdn.com/b/sqlazure/archive/2010/09/07/10058942.aspx  That is working fine, no issue with the Azure side (this is not an Azure question).

I have now encrypted the connection strings in my app.config file of my windows app, and have imported the .pfx certificate into my certificate store. When I run my app after just importing the certificate, it works fine. It decrypts the connection strings and works. After I reboot however, it fails because it does not have access to the private key in the .pfx file. I assume that's because the private key needs to be authenticated again.

I am a newbie to encryption, and although I've spent the past few days finding what I can, but I can't crack the right way to work with this.

How can I embed the private key in the .pfx file, so when I run the app on my development machine, it will have access to the private key & work?

Thanks, +M

Encrypt connection strings in web config




We have website hosted on shared server with SQL Server 2005 as database. Now that database server is also shared by other people and hence we have to use SQL Server authentication and we have stored those connection strings in our web.config file.


Can we encrypt connection strings? I found few ways to encrypt but in all of them I have to have access to the server and that I don't have.


Pls help.



Surface Area Configuration for Features Connection Issues


I have a full SQL Server 2005 installation (default instance "MSSQLServer") plus an instance named "Microsoft##SSEE" (I believe a Sharepoint admin database instance).  I need to configure the features on the default instance.  When I try to open up Surface Area Configuration for Features for the local host, I get the message below.  The message does not provide anything of value.  What is going on and how am I supposed to administer this server?  Am I missing something obvious.

Thanks in advance,

Greg Wilkerson


TITLE: Surface Area Configuration

Failed to connect to server localhost\MICROSOFT##SSEE. (Microsoft.SqlServer.ConnectionInfo)


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (Microsoft SQL Server, Error: -1)

For help, click:

Three Tier Architecture with ASP.NET

ASP.NET supports layered architecture, and this article will illustrate how it can work with the ASP.NET presentation controls. This article focuses mainly on the GridView control, mostly because it is prevalently used in .NET development. However, the concepts work for other controls as well.

Like Celebrities - info about all celebrities

Like Celebrities - info about all celebrities

3-tier architecture in C# sample

This article discusses and implements 3-tier architecture using C# and a dummy customer using MS Access database. In this article I am trying to implement a small reusable component that maintains customers in 3-tier architecture. It shows how to add, update and find customer details.

Three Tier Architecture with ASP.NET

In my previous two articles, we talked about the use of layers, and the many different options that can be used to develop layered architecture. Layered architectures are essentially objects and work in object-oriented environments, such as ASP.NET. ASP.NET supports layered architecture, and this article will illustrate how it can work with the ASP.NET presentation controls. This article focuses mainly on the GridView control, mostly because it is prevalently used in .NET development. However, the concepts work for other controls as well.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend