Solved

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

Posted on 2008-10-20
5
494 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
ID: 22760469
0
 

Author Comment

by:UnderSeven
ID: 22762076
My code is actually erroring on the connection string.  
0
 

Author Comment

by:UnderSeven
ID: 22762255
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
ID: 22764363
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
ID: 31507928
Thanks.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

920 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

17 Experts available now in Live!

Get 1:1 Help Now