0

I have spent literally a 1 1/2 days Googling for a solution to this issue to no avail.

I am unable to reference a compiled SQLCLR assembly from code, in another project. I can add the reference to the other project, but when I try to add a "using" directive to include the referenced component in code, I receive a "The type or namespace name 'Database1' could not be found (are you missing a using directive or an assembly reference?)"

Here's what I've done:

  1. Using VS 2012/2013 I have created a blank solution.
  2. Added a new SQL Server Database project (Database1) targeting SQL Server 2012, and the .Net 4.5 Framework (NOT the Client Profile).
  3. Added a new command line/winform/web app/whatever project (TestConsoleApplication1) to the solution, that ALSO targets the .Net 4.5 Framework (NOT the Client Profile).
  4. Added references to the Database1 assembly (have tried project reference as well), and the System.Data assembly to the TestConsoleApplication1 project.
  5. Added using directive for the System.Data assembly to the default class which was automatically added when I created the TestConsoleApplication1 project.
  6. Attempted to add a using directive for the Database1 assembly to the default class which was automatically added when I created the TestConsoleApplication1 project.
  7. When attempting to add the using directive for the Database1 assembly, the assembly name did not appear in intellisense, and typing in the assembly name resulted in the "red squiggle" under Database1.
  8. Attempted to build the project, results in the "The type or namespace name 'Database1' could not be found (are you missing a using directive or an assembly reference?)" Error.
  9. Checked, double, triple, quadruple...n-tuple-checked that both projects target the same .Net Framework version (4.5).

Database1 has no code, and here is the code for the "client" app (TestConsoleApplication1):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Database1; //Marked as design-time error, and throws ERROR on build

namespace TestConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {


        }
    }
}

Does anybody have any idea why I can add a reference to the SQLCLR assembly, but the "client" project code appears unable to actually "see" nor access the referenced assembly?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • Are you sure you have the right namespace? i.e., the assembly may be named `Database1`, but perhaps the namespace is something like `CompanyName.Database1` or some such? The `using` directive uses the namespace, the project reference uses the assembly name. – Tim May 19 '14 at 20:38
  • Yes. As this is just a "test" solution, the namespace and assembly names are the same (Database1). Thanks. – TDub_At_Harrison1 May 19 '14 at 22:20

1 Answers1

1

Your .net console project can not reference the .Net assembly that is within the SQLCLR project as it will be embedded in the database when you publish it. It does combile to a DLL but would be dependant on the Microsoft Sql Server libs and would normally run under the same connection context vs a defined connection string to talk back to the database. Both projects could reference a third, shared assembly, then add SQLCLR .net code directly in the database project that simply calls the shared code as a wrapper.

Steve
  • 1,995
  • 2
  • 16
  • 25
  • I'm sorry, but that is not true. I am able to add a reference to another SQLCLR assembly, and the namespace is accessible via a using directive. I've tried creating the Database1 assembly with identical properties (even signing w/strong keyfile name), but I can't make it accessible in the "client" app. There appears to be something I'm missing, or perhaps an anomaly was introduced when I installed VS 2013. In any case, I know what I'm trying to do is doable, or at least has been done before. Thanks. – TDub_At_Harrison1 May 20 '14 at 15:57