Solved

Trying to make a connection in C# to a SQLserver db for a CLR trigger

Posted on 2008-10-20
5
492 Views
Last Modified: 2012-05-05
I have more or less borrowed the code that is supposed to make this possible, but it isn't working.  I appaer to by misusing the SQLconnection class.  I've done this before in vb but obviously c# is a little different.  Here is the code I am currently trying to use.

Any help pointing me toward the right direction woudl be appreciated.
using System;
 

using System.Data;

using System.Data.Sql;

using Microsoft.SqlServer.Server;

using System.Data.SqlClient;

using System.Data.SqlTypes;

using System.Xml;
 
 

public class tat_io_trigger

{

    public static void Main()

    {

        SqlTriggerContext triggContext = SqlContext.TriggerContext;

        Sqlconnection conn = new SqlConnection ("context connection = true");

        conn.open();

        SqlCommand sqlComm = conn.CreateCommand();

        SqlPipe sqlP = SqlContext.Pipe;

        SqlDataReader dr;

            sqlComm.CommandText = "Exec sp_gettatdata";
 
 

    }

}

Open in new window

0
Comment
Question by:UnderSeven
  • 3
  • 2
5 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
Comment Utility
0
 

Author Comment

by:UnderSeven
Comment Utility
My code is actually erroring on the connection string.  
0
 

Author Comment

by:UnderSeven
Comment Utility
I am getting this error

Error      1      The type 'System.Data.SqlClient.SqlConnection' exists in both 'c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll' and 'c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll'      H:\My Documents\Visual Studio 2005\Projects\tat_io_scheduler\tat_io_scheduler\CodeFile1.cs      16      9      tat_io_scheduler


I don't see why, the two libraries it is complaining about are both necessary.  
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 125 total points
Comment Utility
the error is self explanatory
you are trying to reference the system.data.dll from 2 places
one from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll
and other from c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll

check and remove one of the references from your project
better one to be removed will be the c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\System.Data.SqlClient.dll
0
 

Author Closing Comment

by:UnderSeven
Comment Utility
Thanks.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 34
Windows Service to Receive TCP Packets 4 30
Trouble with References... 5 22
ConsoleSql 1 14
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now