Connection String in DAL

Hi,
I'm developping an enterprise app and have defined a data access layer in which I have my entities classes and the data access classes. I've defined a the connection string in the data access layer application to a the local northwind database.  ee the example code for the employee entity and data access classes:

public class Employee
    {
        private int employeeID;
        private string firstName;
        private string lastName;
        //private string title;
        private string titleOfCourtesy;
        //private DateTime birthDate;

        public int EmployeeID
        {
            get { return employeeID; }
            set { employeeID = value; }
        }

        public string FirstName
        {
            get { return firstName; }
            set { firstName = value; }
        }

        public string LastName
        {
            get { return lastName; }
            set { lastName = value; }
        }

        public string TitleOfCourtesy
        {
            get { return titleOfCourtesy; }
            set { titleOfCourtesy = value; }
        }
    }

//data access class
[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<Employee> GetEmployees()
        {
            UtilityClass uC = new UtilityClass();
            string conString = string.Empty;
            foreach (ConnectionStringSettings  s in ConfigurationManager.ConnectionStrings)
            {
                Console.WriteLine(s.ToString());

            }
           
            conString = ConfigurationManager.ConnectionStrings["Northwind"].ConnectionString;

            SqlConnection cnNwind = new SqlConnection(conString);
            cnNwind.Open();
            SqlCommand cmd = new SqlCommand("GetAllEmployees", cnNwind);

            List<Employee> employees = new List<Employee>();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Employee emp = new Employee();
                emp.EmployeeID = (int)reader["EmployeeID"];
                emp.FirstName = (string)reader["FirstName"];
                emp.LastName = (string)reader["LastName"];
             
                emp.TitleOfCourtesy = (string)reader["TitleOfCourtesy"];
               
                employees.Add(emp);
            }

            return employees;
        }


    }

In my client application, when I instanciate the Employee class, it can not find the connection string I've defined into the configuration file.

It looks like the employee class is looking for the connection string in the client application configuration file instead of in the data access layer aplication configuration file even though the employee class is defined in the data access layer class.

Any idea???
racinecondeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lazyberezovskyCommented:
Configuration is taken from .exe file config (App.config), not from dll config file. You should add your DAL configuration settings to application configuration file.
0
lazyberezovskyCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
arundhajCommented:
Your question has the answer.

Your DAL application is a DLL and it is being reference from the client application, right? In that case, your client application should also have the key for "Northwind" in the configuration file.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.