Solved

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

Posted on 2008-10-20
5
499 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 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