Hi,
I have searched and searched the net...but just cant get my code to work. I have an external "ConnectionStrings.config" file that has the database connection string. Im trying to connect to the database, but the code just does not work. I have no idea what it is that Im doing wrong. I have included the code in the ConnectionStrings.config file, and for the DABasics.cs file. Please can someone tell me what Im doing wrong?
ConnectionStrings.config
<connectionStrings>
<clear />
<add name="TimeManagement" connectionString="server=DEVSERVER;database=TimeManagement;uid=sa;pwd=XXX;" providerName="System.Data.SqlClient" />
</connectionStrings>
DABasics.cs
using System;
using System.Web.Configuration;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
namespace TimeManagement
{
/// <summary>
/// This is the super class for Data Access Classes
/// </summary>
class DABasis
{
protected static string strConnect;
public DABasis()
{
}
/// <summary>
/// Please see the web.config file
/// </summary>
static DABasis()
{
Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("ConnectionStrings.config");
ConnectionStringSettings connString = rootWebConfig.ConnectionStrings.ConnectionStrings["connectionStrings"];
strConnect = connString.ConnectionString;
}
/// <summary>
/// Gets a SqlConnection to the local sqlserver
/// </summary>
/// <returns>SqlConnection</returns>
protected SqlConnection GetConnection()
{
SqlConnection oConnection = new SqlConnection(strConnect);
return oConnection;
}
}
}
ERROR MESSAGES I GET:
Error 1 The type or namespace name 'Configuration' could not be found (are you missing a using directive or an assembly reference?) C:\_ASPNetWebsites\TimeManagement\DABasis.cs 25 13 TimeManagement
Error 2 The type 'System.Configuration.Configuration' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. C:\_ASPNetWebsites\TimeManagement\DABasis.cs 25 13 TimeManagement
Error 3 The type or namespace name 'ConnectionStringSettings' could not be found (are you missing a using directive or an assembly reference?) C:\_ASPNetWebsites\TimeManagement\DABasis.cs 26 13 TimeManagement