Solved

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

Posted on 2008-10-20
5
496 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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