locked
LINQ to SQL issues RRS feed

  • Question

  • User821252117 posted

     Ok, when I first installed IIS/ASP.NET all code I wrote was working but kentico, a system I needed to try out was not working.  So I went throught the process of uninstalling everything and reinstalling everything and now kenetico works but If i try to use LINQ to SQL I get a runtime error(code compiles fine) stating:

     CS0246: The type or namespace name 'DataClassesDataContext' could not be found (are you missing a using directive or an assembly reference?)

    I am adding the LINQ to SQL the same way as before, what could be causing this issue?

    Thursday, February 12, 2009 3:36 PM

Answers

  • User1716267170 posted

    Hi eridius,

    LINQ-SQL requires .net framework 3.5, you need to validate it first. If you're using .net framework 3.5, you may miss adding the reference to System.Data.Linq assembly. To achieve it, you could follow these steps:

    1) Right click your project and select "Add Reference".

    2) Select .NET tab and search System.Data.Linq.

    3) Click OK to add it.

    Also, I'm afraid you're missing the namespace. First, you need to check you've include "System.Data.Linq" namespace in the page. Also, you need to whether you have a namespace for your DataContext - go to the generated source code to check it.

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 15, 2009 10:17 PM

All replies

  • User821252117 posted

     anyone know what might cause this as i really don't want to try the reinstall method again?

    Friday, February 13, 2009 10:00 AM
  • User1716267170 posted

    Hi eridius,

    LINQ-SQL requires .net framework 3.5, you need to validate it first. If you're using .net framework 3.5, you may miss adding the reference to System.Data.Linq assembly. To achieve it, you could follow these steps:

    1) Right click your project and select "Add Reference".

    2) Select .NET tab and search System.Data.Linq.

    3) Click OK to add it.

    Also, I'm afraid you're missing the namespace. First, you need to check you've include "System.Data.Linq" namespace in the page. Also, you need to whether you have a namespace for your DataContext - go to the generated source code to check it.

    Thanks.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 15, 2009 10:17 PM
  • User66127908 posted

    Hi

    i am getting the same problem.

    i have built the mydb.dbml file in the App_Code directory and in the pages i use mydbDataContext to map the database and use LINQ queries to fill the data. it runs fine on my local machine. but when i publish the website to the hosting server (which support .net 3.5 etc) and run the page it says:

    CS0246: The type or namespace name 'mydbDataContext' could not be found (are you missing a using directive or an assembly reference?)

    i have checked suggestions you mentioned but it still gives me this error. any ideas?

    many thanks

    Jim

    Sunday, March 1, 2009 12:19 PM
  • User654007845 posted

    Hi Jim,
      I have the same issue right now. Have you had any luck with an fix ?
      Thanks for your time.

    iqworks

    Sunday, March 1, 2009 9:29 PM
  • User66127908 posted

    Hi iqworks,

    Sort of. What happen is that when you add a LINQ to SQL class in VS2008 (the .dbml file), it recommends you to add it to the App_Code folder. When you publish your website, VS precompiles the code and then copies all the files including this App_Code folder across to the hosting server. But IIS sounds not allow the App_Code folder coexists with the precompiled files. As such I have to delete the App_Code folder. The website runs, but when I hit the page with the DataContext, it gives the error mentioned before since the .dbml files have been deleted!

    I then delete all files from the server and just did a Copy Web Site from VS. This time it just copies all the source across and doesn't compile. Hence no conflicts with the App_Code folder. I guess when somebody hit your website, the IIS does the compile for you on the server. By doing this, the error disappears.

    Can somebody from Microsoft gives a hint please?

    Cheers,

    Jim

    Monday, March 2, 2009 6:20 PM
  • User66127908 posted

    sorry, hit the wrong button it posted twice.

    Monday, March 2, 2009 6:21 PM
  • User1563039595 posted

    I just ran into the same problem but caused it a different way. I excluded the dbml file, did some work and had to reinclude it. That's when the error resurfaced. The only way around it was to recreate the dbml. Luckily it was a very simple version of it.

    I'm thinking that somehow the designer file was out of sync with the dbml file. So, recreating it synced em up, recompile and everything as happy - no error.

     

    Hope that helps!

     

     

    Monday, May 4, 2009 3:59 PM
  • User1005758432 posted

    Hi eridius,

    LINQ-SQL requires .net framework 3.5, you need to validate it first. If you're using .net framework 3.5, you may miss adding the reference to System.Data.Linq assembly. To achieve it, you could follow these steps:

    1) Right click your project and select "Add Reference".

    2) Select .NET tab and search System.Data.Linq.

    3) Click OK to add it.

    Also, I'm afraid you're missing the namespace. First, you need to check you've include "System.Data.Linq" namespace in the page. Also, you need to whether you have a namespace for your DataContext - go to the generated source code to check it.

    Thanks.

    I got all of these but still receive the same error. Any idea?

    Tuesday, October 26, 2010 12:42 PM
  • User-910927155 posted

    Did you already have a copy of the  .dbml file, add a second one, then clean up by removing the first and renaming the second?

    I did this and found an intresting bug.  The renaming feature does not go in and renamed all the classes on the DatClasses.designer.css file, so while DataClassesDataContext was not found, DataClasses2DataContext was.  This is in the Web Developer 2010 Express client.

    Sunday, November 28, 2010 3:22 PM