Hello, I am currently working on a project for my degree using
asp.net, C# and Sql. The problem I am having is with my connection.cs
file that I have created, the code I have is as follows:
using System;
using System.Configuration;
using System.Linq;
using System.Data.Linq;
using System.Xml;
using School.SchoolCore.Core.Domain;
using School.SchoolCore.Properties;
using StructureMap;
namespace School.SchoolCore.Core.DataAccess.Impl
{
public class Connection
{
public SchoolDataContext GetContext()
{
string connString = "";
try
{
XmlDocument doc = new XmlDocument();
doc.Load("ConnectionStringToUse.xml");
XmlNodeList xnl = doc.GetElementsByTagName("environment");
XmlElement xe = (XmlElement) xnl[0];
switch (xe.InnerText.ToString().ToLower())
{
case "local":
connString = Settings.Default.SchoolConnectionStringLocal;
break;
case "development":
connString = Settings.Default.SchoolConnectionStringDevelopment;
break;
case "production":
connString = Settings.Default.SchoolConnectionStringProduction;
break;
default:
throw new Exception("No connection string defined in app.config!");
}
}
catch
{
connString = Settings.Default.SchoolConnectionStringLocal;
}
SchoolDataContext fdc = new SchoolDataContext(connString);
return fdc;
}
}
}
I think the problem is that the using directives are not all being used as they should. I have resharper on visual studio and it is saying that these three directives:
using System.Configuration;
using System.Linq;
using System.Data.Linq;
are not required and can be removed from code. however I think because it is not actually using.sytem.linq it is not recognising my connString.
I'm relativly new to asp.net and C# so apologise if this all sounds like gobble d goop.
I would really appreciate any help offered.
many thanks